Created
December 25, 2011 09:57
-
-
Save ethertank/1519024 to your computer and use it in GitHub Desktop.
detect audio element supported
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var audioElementSupported = (function(d) { | |
var a = d.createElement("audio"), | |
o = {}, | |
s = "audio\/"; | |
if (typeof a.canPlayType === "function") { | |
o.supported = Boolean(true); | |
o.mp3 = a.canPlayType(s + "mpeg"); | |
o.wav = a.canPlayType(s + 'wav; codecs="1"'); | |
o.ogg = a.canPlayType(s + 'ogg; codecs="vorbis"'); | |
o.m4a = a.canPlayType(s + "x-m4a") || a.canPlayType(s + "aac"); | |
o.webm = a.canPlayType(s + 'webm; codecs="vorbis"'); | |
} else { | |
o.supported = Boolean(0); | |
} | |
return o; | |
})(this.document); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## usage ## | |
document.write( | |
audioElementSupported.supported + "<br />" + | |
audioElementSupported.mp3 + "<br />" + | |
audioElementSupported.wav + "<br />" + | |
audioElementSupported.ogg + "<br />" + | |
audioElementSupported.m4a + "<br />" + | |
audioElementSupported.webm + "<br />" | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment