Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 46 additions & 18 deletions docs/source/VideoStream.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "e51d8a045d6645e9b5b2f56ad9dafa80",
"model_id": "27400f5f62934e9b8f2348eef5dcdf6a",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -79,6 +79,30 @@
"video2"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "27400f5f62934e9b8f2348eef5dcdf6a",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"VideoStream(duration=33.158095, video=Video(value=b'./Big.Buck.Bunny.mp4', format='url'))"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"video2"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -96,7 +120,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -115,38 +139,41 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "c4cf93ca86854231809a00fd92e48e2e",
"model_id": "48de1cc1a9374bba8ec6170f215f2be1",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"VBox(children=(VideoStream(video=Video(value=b'./Big.Buck.Bunny.mp4', format='url')), ToggleButton(value=False…"
"VBox(children=(VideoStream(currentTime=3.658572, duration=33.158095, video=Video(value=b'./Big.Buck.Bunny.mp4'…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import ipywidgets as widgets\n",
"from ipywidgets import FloatSlider, ToggleButton, jslink, VBox, HBox\n",
"\n",
"play_button = widgets.ToggleButton(description=\"Play\")\n",
"widgets.jslink((play_button, 'value'), (video2, 'playing'))\n",
"widgets.VBox(children=[video2, play_button])"
"play_button = ToggleButton(description=\"Play\")\n",
"progress_slider = FloatSlider(\n",
" value=video2.currentTime,\n",
" min=0.0,\n",
" max=video2.duration,\n",
" description='progress:',\n",
" orientation='horizontal',\n",
" readout=True,\n",
" readout_format='.1f',\n",
")\n",
"jslink((progress_slider, 'value'), (video2, 'currentTime'))\n",
"jslink((play_button, 'value'), (video2, 'playing'))\n",
"VBox(children=[video2, HBox(children=[play_button, progress_slider])])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -165,7 +192,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.4"
"version": "3.6.6"
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
Expand Down Expand Up @@ -217,7 +244,8 @@
"model_name": "VideoModel",
"state": {
"format": "url",
"layout": "IPY_MODEL_4760ed2c94a84d36a50672c323838103"
"layout": "IPY_MODEL_4760ed2c94a84d36a50672c323838103",
"value": {}
}
},
"c4cf93ca86854231809a00fd92e48e2e": {
Expand Down
10 changes: 6 additions & 4 deletions ipywebrtc/webrtc.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@
except ImportError:
from urllib.request import urlopen # py3
from traitlets import (
observe,
Bool, Bytes, Dict, Instance, Int, List, TraitError, Unicode, validate
observe, Float,
Bool, Dict, Instance, Int, List, TraitError, Unicode, validate
)
from ipywidgets import DOMWidget, Image, Video, Audio, register, widget_serialization
from ipython_genutils.py3compat import string_types
import ipywebrtc._version
import traitlets
import ipywidgets as widgets

logger = logging.getLogger("jupyter-webrtc")
semver_range_frontend = "~" + ipywebrtc._version.__version_js__
Expand Down Expand Up @@ -142,6 +140,8 @@ class VideoStream(MediaStream):
help="An ipywidgets.Video instance that will be the source of the media stream."
).tag(sync=True, **widget_serialization)
playing = Bool(True, help='Plays the videostream or pauses it.').tag(sync=True)
currentTime = Float(0.0, help='The current time of the video.').tag(sync=True)
duration = Float(0.0, help='The duration of the video.').tag(sync=True)

@classmethod
def from_file(cls, filename, **kwargs):
Expand Down Expand Up @@ -204,6 +204,8 @@ class AudioStream(MediaStream):
help="An ipywidgets.Audio instance that will be the source of the media stream."
).tag(sync=True, **widget_serialization)
playing = Bool(True, help='Plays the audiostream or pauses it.').tag(sync=True)
currentTime = Float(0.0, help='The current time of the audio.').tag(sync=True)
duration = Float(0.0, help='The duration of the audio.').tag(sync=True)

@classmethod
def from_file(cls, filename, **kwargs):
Expand Down
Loading