Skip to content

Instantly share code, notes, and snippets.

@cabbiepete
Created February 3, 2011 10:43
Show Gist options
  • Save cabbiepete/809336 to your computer and use it in GitHub Desktop.
Save cabbiepete/809336 to your computer and use it in GitHub Desktop.
cross browser html 5 audio playback example
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