##// END OF EJS Templates
Add option for video html display.
Matthieu Ancellin -
Show More
@@ -0,0 +1,4 b''
1 Video HTML attributes
2 =====================
3
4 Add an option to `IPython.display.Video` to change the attributes of the HTML display of the video.
@@ -1308,7 +1308,7 b' class Image(DisplayObject):'
1308 class Video(DisplayObject):
1308 class Video(DisplayObject):
1309
1309
1310 def __init__(self, data=None, url=None, filename=None, embed=False,
1310 def __init__(self, data=None, url=None, filename=None, embed=False,
1311 mimetype=None, width=None, height=None):
1311 mimetype=None, width=None, height=None, html_attributes="controls"):
1312 """Create a video object given raw data or an URL.
1312 """Create a video object given raw data or an URL.
1313
1313
1314 When this object is returned by an input cell or passed to the
1314 When this object is returned by an input cell or passed to the
@@ -1346,6 +1346,11 b' class Video(DisplayObject):'
1346 height : int
1346 height : int
1347 Height in pixels to which to constrain the video in html.
1347 Height in pixels to which to constrain the video in html.
1348 If not supplied, defaults to the height of the video.
1348 If not supplied, defaults to the height of the video.
1349 html_attributes : str
1350 Attributes for the HTML `<video>` block.
1351 Default: "controls" to get video controls.
1352 Other examples: "controls muted" for muted video with controls,
1353 "loop autoplay" for looping autoplaying video without controls.
1349
1354
1350 Examples
1355 Examples
1351 --------
1356 --------
@@ -1377,6 +1382,7 b' class Video(DisplayObject):'
1377 self.embed = embed
1382 self.embed = embed
1378 self.width = width
1383 self.width = width
1379 self.height = height
1384 self.height = height
1385 self.html_attributes = html_attributes
1380 super(Video, self).__init__(data=data, url=url, filename=filename)
1386 super(Video, self).__init__(data=data, url=url, filename=filename)
1381
1387
1382 def _repr_html_(self):
1388 def _repr_html_(self):
@@ -1390,9 +1396,9 b' class Video(DisplayObject):'
1390 # notebook output.
1396 # notebook output.
1391 if not self.embed:
1397 if not self.embed:
1392 url = self.url if self.url is not None else self.filename
1398 url = self.url if self.url is not None else self.filename
1393 output = """<video src="{0}" controls {1} {2}>
1399 output = """<video src="{0}" {1} {2} {3}>
1394 Your browser does not support the <code>video</code> element.
1400 Your browser does not support the <code>video</code> element.
1395 </video>""".format(url, width, height)
1401 </video>""".format(url, self.html_attributes, width, height)
1396 return output
1402 return output
1397
1403
1398 # Embedded videos are base64-encoded.
1404 # Embedded videos are base64-encoded.
@@ -1411,10 +1417,10 b' class Video(DisplayObject):'
1411 else:
1417 else:
1412 b64_video = b2a_base64(video).decode('ascii').rstrip()
1418 b64_video = b2a_base64(video).decode('ascii').rstrip()
1413
1419
1414 output = """<video controls {0} {1}>
1420 output = """<video {0} {1} {2}>
1415 <source src="data:{2};base64,{3}" type="{2}">
1421 <source src="data:{3};base64,{4}" type="{3}">
1416 Your browser does not support the video tag.
1422 Your browser does not support the video tag.
1417 </video>""".format(width, height, mimetype, b64_video)
1423 </video>""".format(self.html_attributes, width, height, mimetype, b64_video)
1418 return output
1424 return output
1419
1425
1420 def reload(self):
1426 def reload(self):
General Comments 0
You need to be logged in to leave comments. Login now