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?
The hidden attribute hides the <audio> element. You can specify either 'hidden' (without value) or 'hidden="hidden"'. Both are valid. A hidden <audio> element is not visible, but it maintains its position on the page.
The simplest way to automatically play content is to add the autoplay attribute to your <audio> or <video> element.
HTML 5 video autoplay The autoplay feature has actually been built in to HTML 5 video as an additional attribute – the inclusion of which causes the video mentioned in the element to play automatically. The above code will make a video automatically play when the webpage is loaded in the browser.
The audio tag allows you to embed audio content in your HTML pages. By default the browser does not show any controls for this element. Which means the audio will play only if set to autoplay (more on this later) and the user can't see how to stop it, or control the volume or move through the track.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With