Skip to content

Instantly share code, notes, and snippets.

@ethertank
Created December 25, 2011 09:57
Show Gist options
  • Save ethertank/1519024 to your computer and use it in GitHub Desktop.
Save ethertank/1519024 to your computer and use it in GitHub Desktop.
detect audio element supported
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);
## 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