Arvin
Arvin

Reputation: 1014

HTML5 audio is not showing if source is unavailable

In my audio player application if the source is not available the audio player is not showing.

my markup is

<div style="width:500px;height:300px;background-color:#E5EECC;">
    <audio type="audio/mpeg" preload="meta" controls="controls">
        <source src="http://www.tempsite.com/myaudio2.mp3" type="audio/mpeg" />
        <p>Your user agent does not support the HTML5 Audio element.</p>
    </audio>
</div>

Also the message in the "p" tag is not showing. Is there any way to show that audio player or atleast the message.I tried onerror attribute(dont know whether it is a valid attribute)that also failed.

I have made a fiddle http://jsfiddle.net/D9f5T/2/

Upvotes: 1

Views: 241

Answers (1)

user3423360
user3423360

Reputation: 36

Add the onerror attribute in source tag.

<div style="width:500px;height:300px;background-color:#E5EECC;">
    <audio type="audio/mpeg" preload="meta" controls="controls">
        <source onerror="alert('error')" src="http://www.tempsite.com/myaudio2.mp3" type="audio/mpeg" />
        <p>Your user agent does not support the HTML5 Audio element.</p>
    </audio>
</div>

Upvotes: 2

Related Questions