Created
May 14, 2010 15:56
-
-
Save dmdeller/401324 to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* thanks to Mark Pilgrim: | |
* http://diveintohtml5.org/everything.html | |
* http://diveintohtml5.org/detect.html#techniques | |
*/ | |
function check_html5_audio() | |
{ | |
// avoid repeating the check unnecessarily | |
if (typeof browser_supports_html5_audio != "undefined") | |
{ | |
return browser_supports_html5_audio; | |
} | |
browser_supports_html5_audio = false; | |
// check if browser supports <audio> tag | |
var a = document.createElement('audio'); | |
if (!a.canPlayType) | |
{ | |
return false; | |
} | |
// check if browser supports MP3; Firefox supports <audio> but only for Ogg Vorbis | |
if (!(a.canPlayType('audio/mpeg;').replace(/no/, ''))) | |
{ | |
return false; | |
} | |
// check if browser supports preload attribute; older versions of Safari do not. | |
// for podcast pages, automatically loading every <audio> element on the page is unacceptable. | |
// https://bugs.webkit.org/show_bug.cgi?id=25267 | |
// https://bugs.webkit.org/show_bug.cgi?id=35385 | |
// http://daringfireball.net/2009/12/html5_video_unusable | |
a.setAttribute("preload", "none"); | |
if (a.preload != "none") | |
{ | |
return false; | |
} | |
browser_supports_html5_audio = true; | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment