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 |
@@ -1267,7 +1267,8 b' class Image(DisplayObject):' | |||||
1267 |
|
1267 | |||
1268 | class Video(DisplayObject): |
|
1268 | class Video(DisplayObject): | |
1269 |
|
1269 | |||
1270 |
def __init__(self, data=None, url=None, filename=None, embed=False, |
|
1270 | def __init__(self, data=None, url=None, filename=None, embed=False, | |
|
1271 | mimetype=None, width=None, height=None): | |||
1271 | """Create a video object given raw data or an URL. |
|
1272 | """Create a video object given raw data or an URL. | |
1272 |
|
1273 | |||
1273 | When this object is returned by an input cell or passed to the |
|
1274 | When this object is returned by an input cell or passed to the | |
@@ -1299,6 +1300,12 b' class Video(DisplayObject):' | |||||
1299 | mimetype: unicode |
|
1300 | mimetype: unicode | |
1300 | Specify the mimetype for embedded videos. |
|
1301 | Specify the mimetype for embedded videos. | |
1301 | Default will be guessed from file extension, if available. |
|
1302 | Default will be guessed from file extension, if available. | |
|
1303 | width : int | |||
|
1304 | Width in pixels to which to constrain the video in HTML. | |||
|
1305 | If not supplied, defaults to the width of the video. | |||
|
1306 | height : int | |||
|
1307 | Height in pixels to which to constrain the video in html. | |||
|
1308 | If not supplied, defaults to the height of the video. | |||
1302 |
|
1309 | |||
1303 | Examples |
|
1310 | Examples | |
1304 | -------- |
|
1311 | -------- | |
@@ -1325,16 +1332,24 b' class Video(DisplayObject):' | |||||
1325 |
|
1332 | |||
1326 | self.mimetype = mimetype |
|
1333 | self.mimetype = mimetype | |
1327 | self.embed = embed |
|
1334 | self.embed = embed | |
|
1335 | self.width = width | |||
|
1336 | self.height = height | |||
1328 | super(Video, self).__init__(data=data, url=url, filename=filename) |
|
1337 | super(Video, self).__init__(data=data, url=url, filename=filename) | |
1329 |
|
1338 | |||
1330 | def _repr_html_(self): |
|
1339 | def _repr_html_(self): | |
|
1340 | width = height = '' | |||
|
1341 | if self.width: | |||
|
1342 | width = ' width="%d"' % self.width | |||
|
1343 | if self.height: | |||
|
1344 | height = ' height="%d"' % self.height | |||
|
1345 | ||||
1331 | # External URLs and potentially local files are not embedded into the |
|
1346 | # External URLs and potentially local files are not embedded into the | |
1332 | # notebook output. |
|
1347 | # notebook output. | |
1333 | if not self.embed: |
|
1348 | if not self.embed: | |
1334 | url = self.url if self.url is not None else self.filename |
|
1349 | url = self.url if self.url is not None else self.filename | |
1335 | output = """<video src="{0}" controls> |
|
1350 | output = """<video src="{0}" controls {1} {2}> | |
1336 | Your browser does not support the <code>video</code> element. |
|
1351 | Your browser does not support the <code>video</code> element. | |
1337 | </video>""".format(url) |
|
1352 | </video>""".format(url, width, height) | |
1338 | return output |
|
1353 | return output | |
1339 |
|
1354 | |||
1340 | # Embedded videos are base64-encoded. |
|
1355 | # Embedded videos are base64-encoded. | |
@@ -1353,10 +1368,10 b' class Video(DisplayObject):' | |||||
1353 | else: |
|
1368 | else: | |
1354 | b64_video = b2a_base64(video).decode('ascii').rstrip() |
|
1369 | b64_video = b2a_base64(video).decode('ascii').rstrip() | |
1355 |
|
1370 | |||
1356 | output = """<video controls> |
|
1371 | output = """<video controls {0} {1}> | |
1357 |
<source src="data:{ |
|
1372 | <source src="data:{2};base64,{3}" type="{2}"> | |
1358 | Your browser does not support the video tag. |
|
1373 | Your browser does not support the video tag. | |
1359 | </video>""".format(mimetype, b64_video) |
|
1374 | </video>""".format(width, height, mimetype, b64_video) | |
1360 | return output |
|
1375 | return output | |
1361 |
|
1376 | |||
1362 | def reload(self): |
|
1377 | def reload(self): |
General Comments 0
You need to be logged in to leave comments.
Login now