Reputation: 403
I am trying to make a music automatically playing when a HTML page is loaded. I tried different things but without success.
I searched through stackoverflow to find a good solution, but didn't manage to find a strong workaround that works with all browsers.
Any help would be greatly appreciated !
Best Regards, Cedric
Upvotes: 0
Views: 909
Reputation: 472
<audio controls autoplay>
<source src="music.mp3" type="audio/mpeg">
</audio>
Upvotes: 0
Reputation: 310
While the autoplay
attribute works on some cases, you should know that in many cases it doesn't. I suggest you read this MDN article to understand why and also get some ideas how to adapt to the limitations.
Upvotes: 1
Reputation: 41
I think this code will work for you ! Works perfectly fine for me!
<audio controls autoplay>
<source src="audiofile.mp3" type="audio/mpeg">
</audio>
Upvotes: 0
Reputation: 759
The <audio>
element with the autoplay
attribute should be sufficient. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio
It is extremely well supported.
Upvotes: 0