In safari 5, new Audio is not supported, so the error console displays :
TypeError : 'undefined' is not a constructor (evaluating 'new Audio')
How could I programatically know whether new Audio is supported by browser ?
There are three supported audio formats in HTML: MP3, WAV, and OGG.
Note: Nearly all browsers support MP3 — for more details see this page on media format browser compatibility.
If the browser doesn't support the audio element, then it will display the message, “Sorry, but your browser doesn't support audio.”
HTML5 features include native audio and video support without the need for Flash.
I guess you might just try it...
var createAudio = function() {
try {
return new Audio();
} catch(e) {
return false;
}
};
var audio = createAudio();
if(audio) {
// start playing... or check formats etc.
}
In case there is exception, the Audio class does not exist and returns false.
For more detailed solution check Modernzr library: http://modernizr.com/docs/#audio
The related solution is here Detecting html5 audio support with Modernizr
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