For the life of me, I cannot find a plete listing of all html5 <audio>
events and attributes (though I believe they may vary between browsers). A lot of my googling has websites talking about "using the javascript audio api" or "with the javascript audio api," etc. and shows a couple of examples, but I haven't found a list of methods or what they do.
For example,
var a = document.getElementById('audio');
a.ended = function () { alert('foo!'); }; //FAIL
a.onended = function () { alert('foo!'); }; //FAIL
a.addEventListener('ended', function () { alert('foo!'}); }; //PASS
a.addEventListener('play', function () { alert('foo!'}); };
Why is there no onended
? Why is it called play
instead of played
? These things aren't intuitive, so an actual list of the API would help a lot.
Additionally, do some browsers not respect the above attributes? My blackberry phone and mobile-ie9 won't alert on the ended event, but chrome, ffx, and ipad-safari all do.
For the life of me, I cannot find a plete listing of all html5 <audio>
events and attributes (though I believe they may vary between browsers). A lot of my googling has websites talking about "using the javascript audio api" or "with the javascript audio api," etc. and shows a couple of examples, but I haven't found a list of methods or what they do.
For example,
var a = document.getElementById('audio');
a.ended = function () { alert('foo!'); }; //FAIL
a.onended = function () { alert('foo!'); }; //FAIL
a.addEventListener('ended', function () { alert('foo!'}); }; //PASS
a.addEventListener('play', function () { alert('foo!'}); };
Why is there no onended
? Why is it called play
instead of played
? These things aren't intuitive, so an actual list of the API would help a lot.
Additionally, do some browsers not respect the above attributes? My blackberry phone and mobile-ie9 won't alert on the ended event, but chrome, ffx, and ipad-safari all do.
Share Improve this question asked Dec 2, 2011 at 15:29 Explosion PillsExplosion Pills 192k55 gold badges340 silver badges416 bronze badges 2- Support for HTML 5 is still universally pretty bad, and IE isn't exactly notorious for playing nice with standards. A list of the new HTML 5 event handlers for media objects can be found here, but I wouldn't expect wide-ranging support for at least a year or two. – iandisme Commented Dec 2, 2011 at 15:41
-
The
<audio>
element and its JavaScript API are relatively new. Support is likely to be variable for some time. – Paul D. Waite Commented Dec 2, 2011 at 15:43
3 Answers
Reset to default 8- HTML5 spec: the
audio
element - When can I use... audio patibility tables (and links to external resources)
Unfortunately you're experiencing firsthand the fact that there simply is no official JavaScript API for audio (yet).
As you can see from Matt's fine canIuse link
"Consistant cross-browser support for audio is currently a mess in HTML5 ..."
so you should take a look at sound.js ;)
"... but SoundJS works to abstract away the problems and makes adding sound to your games or rich experiences much easier. "
--> Polyfill : SoundJS
w3schools has a useful event, property and method list for audio/video. Although it does not address cross browser concerns:
http://www.w3schools./tags/ref_av_dom.asp