Fallback to the default if source is invalid in AUDIO tag

Go To StackoverFlow.com


So I have a basic audio element. Say I have a single mp3 source. I'm using Firefox. The browser sees the audio tag, likes it, places the controls as directed, but doesn't like any sources, so it doesn't load any audio, but still ignores the default items that a lesser browser would have displayed.

Sadly I'd prefer the browser actually display the default items at that point (say a link to download the mp3) rather than than display the non-working audio controls. Since there is no AudioElement.stuffThatsNotSRC, how do we do this?

So what I do is have a checkSources() that fires onLoad that looks at the networkState and if it finds the 0 or 3 it then goes to a HTML span I have around the audio control and replaces its inner HTML with the non-source stuff that was inside the audio tag.

Is there a better way to do this?

2012-04-04 17:13
by SidMuchRock


Use the source tag to define multiple file types.

<audio controls="true">
    <source src="demo.mp3" type="audio/mp3"> 
    <source src="demo.ogg" type="audio/ogg"> 
    <source src="demo.aac" type="audio/mp4"> 
    <!-- If no support at all. -->
    HTML5 audio not supported 


2012-04-17 22:01
by r j