views:

344

answers:

2

that's all really. If the browser can play MP3's then I'll use the audio tag to play a file. If not, I'll have to load in a flash player.

+2  A: 

Just put the code that displays the flash sound player in the tag.

Edit : Use the canPlayType function : http://www.whatwg.org/specs/web-apps/current-work/multipage/media-elements.html#dom-navigator-canplaytype
You can also look at the error attribute : http://www.whatwg.org/specs/web-apps/current-work/multipage/media-elements.html#dom-media-error

mickael9
you mean like this <audio src='some.mp3'><!-- FLASH HERE --></audio>? That wouldn't work because Chrome (for example) supports the audio tag, but not MP3.
gargantaun
thanks. that led me to this detailed explanation... http://html5doctor.com/native-audio-in-the-browser/
gargantaun
+7  A: 
var audio  = document.createElement("audio"),
canPlayMP3 = (typeof audio.canPlayType === "function" &&
              audio.canPlayType("audio/mpeg") !== "");

Edit: If you don't want to use JavaScript (yes, this will work in browsers that support <audio> but not MP3), try this:

<audio controls="controls">
<source src="some-audio-file.mp3" type="audio/mpeg" />
<!-- if you have an OGG version, also include this:
<source src="some-audio-file.ogg" type="audio/ogg" />
-->
<!-- flash object goes here -->
</audio>

If you want auto-play, include a autoplay attribute on the audio element.

Eli Grey