Show More
@@ -89,7 +89,8 b' class Audio(DisplayObject):' | |||||
89 | """ |
|
89 | """ | |
90 | _read_flags = 'rb' |
|
90 | _read_flags = 'rb' | |
91 |
|
91 | |||
92 |
def __init__(self, data=None, filename=None, url=None, embed=None, rate=None, autoplay=False, normalize=True |
|
92 | def __init__(self, data=None, filename=None, url=None, embed=None, rate=None, autoplay=False, normalize=True, | |
|
93 | element_id=None): | |||
93 | if filename is None and url is None and data is None: |
|
94 | if filename is None and url is None and data is None: | |
94 | raise ValueError("No audio data found. Expecting filename, url, or data.") |
|
95 | raise ValueError("No audio data found. Expecting filename, url, or data.") | |
95 | if embed is False and url is None: |
|
96 | if embed is False and url is None: | |
@@ -100,6 +101,7 b' class Audio(DisplayObject):' | |||||
100 | else: |
|
101 | else: | |
101 | self.embed = True |
|
102 | self.embed = True | |
102 | self.autoplay = autoplay |
|
103 | self.autoplay = autoplay | |
|
104 | self.element_id = element_id | |||
103 | super(Audio, self).__init__(data=data, url=url, filename=filename) |
|
105 | super(Audio, self).__init__(data=data, url=url, filename=filename) | |
104 |
|
106 | |||
105 | if self.data is not None and not isinstance(self.data, bytes): |
|
107 | if self.data is not None and not isinstance(self.data, bytes): | |
@@ -198,12 +200,13 b' class Audio(DisplayObject):' | |||||
198 |
|
200 | |||
199 | def _repr_html_(self): |
|
201 | def _repr_html_(self): | |
200 | src = """ |
|
202 | src = """ | |
201 | <audio controls="controls" {autoplay}> |
|
203 | <audio {element_id} controls="controls" {autoplay}> | |
202 | <source src="{src}" type="{type}" /> |
|
204 | <source src="{src}" type="{type}" /> | |
203 | Your browser does not support the audio element. |
|
205 | Your browser does not support the audio element. | |
204 | </audio> |
|
206 | </audio> | |
205 | """ |
|
207 | """ | |
206 |
return src.format(src=self.src_attr(),type=self.mimetype, autoplay=self.autoplay_attr() |
|
208 | return src.format(src=self.src_attr(), type=self.mimetype, autoplay=self.autoplay_attr(), | |
|
209 | element_id=self.element_id_attr()) | |||
207 |
|
210 | |||
208 | def src_attr(self): |
|
211 | def src_attr(self): | |
209 | import base64 |
|
212 | import base64 | |
@@ -222,6 +225,12 b' class Audio(DisplayObject):' | |||||
222 | else: |
|
225 | else: | |
223 | return '' |
|
226 | return '' | |
224 |
|
227 | |||
|
228 | def element_id_attr(self): | |||
|
229 | if (self.element_id): | |||
|
230 | return 'id="{element_id}"'.format(element_id=self.element_id) | |||
|
231 | else: | |||
|
232 | return '' | |||
|
233 | ||||
225 | class IFrame(object): |
|
234 | class IFrame(object): | |
226 | """ |
|
235 | """ | |
227 | Generic class to embed an iframe in an IPython notebook |
|
236 | Generic class to embed an iframe in an IPython notebook |
General Comments 0
You need to be logged in to leave comments.
Login now