问题
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 hot to play the music without displaying the player?
回答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
回答2:
If you are using React, make sure autoplay is set to,
autoPlay
React wants it to be camelcase!
回答3:
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)
回答4:
I used this code,
<div style="visibility:hidden">
<audio autoplay loop>
<source src="Aakaasam-Yemaaya Chesave.mp3">
</audio>
</div>
It is working well but i want stop and pause button. So, we can stop if we don't want to listen.
回答5:
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
回答6:
<div id="music">
<audio autoplay>
<source src="kooche.mp3" type="audio/mpeg">
<p>If you can read this, your browser does not support the audio element.</p>
</audio>
</div>
And the css:
#music {
display:none;
}
Like suggested above, you probably should have the controls available in some form. Maybe use a toggle link/checkbox that slides the controls in via jquery.
Source: HTML5 Audio Autoplay
回答7:
You Could use this code, It's Works with me
<div style="visibility:hidden">
<audio autoplay loop>
<source src="../audio/audio.mp3">
</audio>
</div>
回答8:
For future reference to people who find this page later you can use:
<audio controls autoplay loop hidden>
<source src="kooche.mp3" type="audio/mpeg">
<p>If you can read this, your browser does not support the audio element.</p>
</audio>
来源:https://stackoverflow.com/questions/20179190/autoplay-an-audio-with-html5-embed-tag-while-the-player-is-invisible