Created
February 3, 2011 10:43
-
-
Save cabbiepete/809336 to your computer and use it in GitHub Desktop.
cross browser html 5 audio playback example
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
function supports_audio() { | |
return !!document.createElement('audio').canPlayType; | |
} | |
function supports_audio_type(audioType) { | |
if (!supports_audio()) { return false; } | |
var a = document.createElement("audio"); | |
return a.canPlayType(audioType); | |
} | |
var alertFile = supports_audio_type("audio/ogg") ? "/sounds/redalert.ogg" : (supports_audio_type("audio/mp4") ? "/sounds/redalert.mp4" : ''); | |
if (alertFile) { | |
var alert = new Audio(alertFile); | |
alert.play(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment