Audio Tag Testing with javaScript Fallback to Flash

Here is an example of implementing the HTML5 audio tag in .ogv, .webm and .mp4 formats. Thanks to Weezer for the song and Matt Coneybeare for the javaScript fallback code.

Audio Testing Code Snippet


<audio id="audioplayer" preload controls loop style="width:424px;">
    <source src="../Files/WeezerSong.mp3" type="audio/mpeg" />
    <source src="../Files/WeezerSong.ogg" type="audio/ogg" />

2. JavaScript

var audioTag = document.createElement('audio');
    if (!(!!(audioTag.canPlayType) && ("no" != audioTag.canPlayType("audio/mpeg")) && ("" != audioTag.canPlayType("audio/mpeg")))) {
    AudioPlayer.embed("audioplayer", { soundFile: "../Files/WeezerSong.mp3" });