Autoplay an audio with HTML5 embed tag while the player is invisible
Solution 1
Alternatively you can try the basic thing to get your need,
<audio autoplay loop>
<source src="johann_sebastian_bach_air.mp3">
</audio>
For further reference click here
Solution 2
If you are using React, make sure autoplay is set to,
autoPlay
React wants it to be camelcase!
Solution 3
You can use this simple code:
<embed src="audio.mp3" AutoPlay loop hidden>
for the result seen here: https://hataken.000webhostapp.com/list-anime.html
Solution 4
Sometimes autoplay is needed. Someone once pointed out that the famous Les Paul Google Doodle (2011) required autoplay, even though the sound didn't play until you moused over the guitar strings. If it's done with class and great design it can be beautiful (especially movie websites with immersive design)
Solution 5
"Sensitive" era
Modern browsers today seem to block (by default) these autoplay features. They are somewhat treated as pop-ops. Very intrusive. So yeah, users now have the complete control on when the sounds are played. [1,2,3]
HTML5 era
<audio controls autoplay loop hidden>
<source src="audio.mp3" type="audio/mpeg">
</audio>
Early days of HTML
<embed src="audio.mp3" style="visibility:hidden" />
References
Nima
Updated on July 05, 2022Comments
-
Nima almost 2 years
I want to autoplay a MP3 audio file and I don't want the player to be visible.
<div id="music"><embed src="Comfortably_Numb.mp3" autostart=true loop=false></div>
When I added
display:none
to the audio tag using css, it doesn't play the music at all. Could someone explain me how to play the music without displaying the player? -
huykon225 about 7 yearsI am using audio tag and it is working perfect but when I check on mobile. Html5 audio tag not sound autoplay. how to fix it ?
-
Daniel over 6 yearsWelcome to Stack Overflow, please review: stackoverflow.com/help/how-to-answer
-
Dan Zuzevich over 6 yearsIf you came here using React, check my answer below.
-
Admin over 5 yearsWhere could you host the mp3?
-
Vinith over 5 yearsHundereds of option to store and stream MP3, common ones are amazon s3, opendrive, kiwi6 etc
-
Kyle Pennell over 4 yearsyou're a savior!