@@ -89,7 +89,8 @@ class Audio(DisplayObject):
8989 """
9090 _read_flags = 'rb'
9191
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 ):
9394 if filename is None and url is None and data is None :
9495 raise ValueError ("No audio data found. Expecting filename, url, or data." )
9596 if embed is False and url is None :
@@ -100,6 +101,7 @@ def __init__(self, data=None, filename=None, url=None, embed=None, rate=None, au
100101 else :
101102 self .embed = True
102103 self .autoplay = autoplay
104+ self .element_id = element_id
103105 super (Audio , self ).__init__ (data = data , url = url , filename = filename )
104106
105107 if self .data is not None and not isinstance (self .data , bytes ):
@@ -198,12 +200,13 @@ def _data_and_metadata(self):
198200
199201 def _repr_html_ (self ):
200202 src = """
201- <audio controls="controls" {autoplay}>
203+ <audio {element_id} controls="controls" {autoplay}>
202204 <source src="{src}" type="{type}" />
203205 Your browser does not support the audio element.
204206 </audio>
205207 """
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 ())
207210
208211 def src_attr (self ):
209212 import base64
@@ -221,6 +224,12 @@ def autoplay_attr(self):
221224 return 'autoplay="autoplay"'
222225 else :
223226 return ''
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 ''
224233
225234class IFrame (object ):
226235 """
0 commit comments