Reputation: 21937
I have a simple HTML5 audio tag on my page. How can I automatically play audio file, when it just will be loaded? Thank you in advance.
Upvotes: 0
Views: 413
Reputation: 2045
Simple way is to put "autoplay" attribute into your "audio" tag. Or you can use some .play() function on the element when the DOM will be ready (or the audio will be preloaded).
Upvotes: 2
Reputation: 76910
You should set the autoplay attribute to "autoplay":
<audio autoplay="autoplay">
<source src="song.ogg" type="audio/ogg" />
</audio>
But since autoplay is a boolean attribute you can just set it
<audio autoplay>
<source src="song.ogg" type="audio/ogg" />
</audio>
Upvotes: 4