##// END OF EJS Templates
Backport PR #12212: Add option to change HTML attributes in display.Video
Matthias Bussonnier -
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 1308 class Video(DisplayObject):
1309 1309
1310 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 1312 """Create a video object given raw data or an URL.
1313 1313
1314 1314 When this object is returned by an input cell or passed to the
@@ -1346,14 +1346,22 b' class Video(DisplayObject):'
1346 1346 height : int
1347 1347 Height in pixels to which to constrain the video in html.
1348 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 1355 Examples
1351 1356 --------
1352 1357
1353 Video('https://archive.org/download/Sita_Sings_the_Blues/Sita_Sings_the_Blues_small.mp4')
1354 Video('path/to/video.mp4')
1355 Video('path/to/video.mp4', embed=True)
1356 Video(b'raw-videodata', embed=True)
1358 ::
1359
1360 Video('https://archive.org/download/Sita_Sings_the_Blues/Sita_Sings_the_Blues_small.mp4')
1361 Video('path/to/video.mp4')
1362 Video('path/to/video.mp4', embed=True)
1363 Video('path/to/video.mp4', embed=True, html_attributes="controls muted autoplay")
1364 Video(b'raw-videodata', embed=True)
1357 1365 """
1358 1366 if isinstance(data, (Path, PurePath)):
1359 1367 data = str(data)
@@ -1377,6 +1385,7 b' class Video(DisplayObject):'
1377 1385 self.embed = embed
1378 1386 self.width = width
1379 1387 self.height = height
1388 self.html_attributes = html_attributes
1380 1389 super(Video, self).__init__(data=data, url=url, filename=filename)
1381 1390
1382 1391 def _repr_html_(self):
@@ -1390,9 +1399,9 b' class Video(DisplayObject):'
1390 1399 # notebook output.
1391 1400 if not self.embed:
1392 1401 url = self.url if self.url is not None else self.filename
1393 output = """<video src="{0}" controls {1} {2}>
1402 output = """<video src="{0}" {1} {2} {3}>
1394 1403 Your browser does not support the <code>video</code> element.
1395 </video>""".format(url, width, height)
1404 </video>""".format(url, self.html_attributes, width, height)
1396 1405 return output
1397 1406
1398 1407 # Embedded videos are base64-encoded.
@@ -1411,10 +1420,10 b' class Video(DisplayObject):'
1411 1420 else:
1412 1421 b64_video = b2a_base64(video).decode('ascii').rstrip()
1413 1422
1414 output = """<video controls {0} {1}>
1415 <source src="data:{2};base64,{3}" type="{2}">
1423 output = """<video {0} {1} {2}>
1424 <source src="data:{3};base64,{4}" type="{3}">
1416 1425 Your browser does not support the video tag.
1417 </video>""".format(width, height, mimetype, b64_video)
1426 </video>""".format(self.html_attributes, width, height, mimetype, b64_video)
1418 1427 return output
1419 1428
1420 1429 def reload(self):
General Comments 0
You need to be logged in to leave comments. Login now