Charlie Charlie - 4 months ago 52x
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?


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" />