Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect HTML5 audio MP3 support?

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.

like image 792
footy Avatar asked Dec 12 '11 01:12

footy


People also ask

Does HTML5 support MP3?

Currently, there are 3 supported “audio formats” for the HTML5 “audio” tag: . mp3, . ogg, and . wav.

Which audio format is not supported by HTML5 audio?

aLaw audio format is not supported by HTML5 audio tag.

Is audio supported in HTML5?

HTML5 Audio is a subject of the HTML5 specification, incorporating audio input, playback, and synthesis, as well as speech to text, in the browser.

Do all browsers support MP3?

Note: Nearly all browsers support MP3 — for more details see this page on media format browser compatibility.


1 Answers

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

like image 154
keyboardP Avatar answered Sep 23 '22 04:09

keyboardP