Explosion Pills
Explosion Pills

Reputation: 191749

Comprehensive html5 Audio API

For the life of me, I cannot find a complete 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.

Upvotes: 5

Views: 6056

Answers (3)

Erik
Erik

Reputation: 479

w3schools has a useful event, property and method list for audio/video. Although it does not address cross browser concerns:

http://www.w3schools.com/tags/ref_av_dom.asp

Upvotes: 0

sebilasse
sebilasse

Reputation: 4618

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

Upvotes: 0

Matt Ball
Matt Ball

Reputation: 359816

Unfortunately you're experiencing firsthand the fact that there simply is no official JavaScript API for audio (yet).

Upvotes: 8

Related Questions