I know how to check in Javascript if HTML5 audio playback is available. But how do I specifically check if MP3 audio playback is available, as IE9 and Chrome support it, while Firefox and Opera do not.
Currently, there are 3 supported “audio formats” for the HTML5 “audio” tag: . mp3, . ogg, and . wav.
aLaw audio format is not supported by HTML5 audio tag.
HTML5 Audio is a subject of the HTML5 specification, incorporating audio input, playback, and synthesis, as well as speech to text, in the browser.
Note: Nearly all browsers support MP3 — for more details see this page on media format browser compatibility.
You could either check the User-Agent and see what browser is being used or you could test support with Javascript.
var a = document.createElement('audio'); return !!(a.canPlayType && a.canPlayType('audio/mpeg;').replace(/no/, ''));
I got the above code from this page.
return !!(a.canPlayType) is better because (some recent versions of)Firefox not supports mp3 and a.canPlayType('audio/mpeg;') will be false
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With