Charlie Charlie - 2 years ago 150
Javascript Question

Have audio tag play after a delay?

I'm playing an MP3 using the

tag in HTML5.

<audio controls="controls" autoplay="autoplay">
<source src="song.mp3" type="audio/mp3" />

This works fine, but I am wondering how I can put a delay in before the song starts to autoplay? I know there's not a
attribute, but I'm thinking it could be accomplished via javascript?

Answer Source

Try this, really simple but you should move the JS outside the markup...

<audio controls="controls" onloadeddata="var audioPlayer = this; setTimeout(function() {; }, 8000)">
    <source src="Kalimba.mp3" type="audio/mp3" />
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download