##// END OF EJS Templates
Add support for width and height arguments when displaying Video...
Dominic Kuang -
Show More
@@ -0,0 +1,1 b''
1 ``IPython.display.Video`` now supports ``width`` and ``height`` arguments, allowing a custom width and height to be set instead of using the video's width and height No newline at end of file
@@ -1256,7 +1256,8 b' class Image(DisplayObject):'
1256
1256
1257 class Video(DisplayObject):
1257 class Video(DisplayObject):
1258
1258
1259 def __init__(self, data=None, url=None, filename=None, embed=False, mimetype=None):
1259 def __init__(self, data=None, url=None, filename=None, embed=False,
1260 mimetype=None, width=None, height=None):
1260 """Create a video object given raw data or an URL.
1261 """Create a video object given raw data or an URL.
1261
1262
1262 When this object is returned by an input cell or passed to the
1263 When this object is returned by an input cell or passed to the
@@ -1288,6 +1289,12 b' class Video(DisplayObject):'
1288 mimetype: unicode
1289 mimetype: unicode
1289 Specify the mimetype for embedded videos.
1290 Specify the mimetype for embedded videos.
1290 Default will be guessed from file extension, if available.
1291 Default will be guessed from file extension, if available.
1292 width : int
1293 Width in pixels to which to constrain the video in HTML.
1294 If not supplied, defaults to the width of the video.
1295 height : int
1296 Height in pixels to which to constrain the video in html.
1297 If not supplied, defaults to the height of the video.
1291
1298
1292 Examples
1299 Examples
1293 --------
1300 --------
@@ -1314,16 +1321,24 b' class Video(DisplayObject):'
1314
1321
1315 self.mimetype = mimetype
1322 self.mimetype = mimetype
1316 self.embed = embed
1323 self.embed = embed
1324 self.width = width
1325 self.height = height
1317 super(Video, self).__init__(data=data, url=url, filename=filename)
1326 super(Video, self).__init__(data=data, url=url, filename=filename)
1318
1327
1319 def _repr_html_(self):
1328 def _repr_html_(self):
1329 width = height = ''
1330 if self.width:
1331 width = ' width="%d"' % self.width
1332 if self.height:
1333 height = ' height="%d"' % self.height
1334
1320 # External URLs and potentially local files are not embedded into the
1335 # External URLs and potentially local files are not embedded into the
1321 # notebook output.
1336 # notebook output.
1322 if not self.embed:
1337 if not self.embed:
1323 url = self.url if self.url is not None else self.filename
1338 url = self.url if self.url is not None else self.filename
1324 output = """<video src="{0}" controls>
1339 output = """<video src="{0}" controls {1} {2}>
1325 Your browser does not support the <code>video</code> element.
1340 Your browser does not support the <code>video</code> element.
1326 </video>""".format(url)
1341 </video>""".format(url, width, height)
1327 return output
1342 return output
1328
1343
1329 # Embedded videos are base64-encoded.
1344 # Embedded videos are base64-encoded.
@@ -1342,10 +1357,10 b' class Video(DisplayObject):'
1342 else:
1357 else:
1343 b64_video = b2a_base64(video).decode('ascii').rstrip()
1358 b64_video = b2a_base64(video).decode('ascii').rstrip()
1344
1359
1345 output = """<video controls>
1360 output = """<video controls {0} {1}>
1346 <source src="data:{0};base64,{1}" type="{0}">
1361 <source src="data:{2};base64,{3}" type="{2}">
1347 Your browser does not support the video tag.
1362 Your browser does not support the video tag.
1348 </video>""".format(mimetype, b64_video)
1363 </video>""".format(width, height, mimetype, b64_video)
1349 return output
1364 return output
1350
1365
1351 def reload(self):
1366 def reload(self):
General Comments 0
You need to be logged in to leave comments. Login now