Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Autoplay an audio with HTML5 embed tag while the player is invisible

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?

like image 960
Nima Avatar asked Nov 24 '13 18:11

Nima


People also ask

How can I make my audio player invisible in HTML?

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.

How do you set an audio tag to play automatically?

The simplest way to automatically play content is to add the autoplay attribute to your <audio> or <video> element.

Can I autoplay a video with sound HTML5?

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.

How do I autoplay audio in HTML without controls?

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.


1 Answers

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

like image 174
Vinith Avatar answered Sep 21 '22 19:09

Vinith