Question

I'm creating this fun little website and I want NyanCat.mp3 to play as soon as the user enters the website and I do not want the controls to be shown.Unfortunately with the code I've got, it only works if the user has controls. I also want it to loop.

Without Controls - Does not work

<audio loop="loop">
<source src="NyanCat.mp3" type="audio/mpeg" />
</audio> 

With Controls - Does work

<audio loop="loop" controls="controls">
<source src="NyanCat.mp3" type="audio/mpeg" />
</audio>
Was it helpful?

Solution

If you don't want the controls to be shown, delete the controls atribute, but add the autoplay atribute instead:

<audio loop="loop" autoplay="autoplay">
    <source src="NyanCat.mp3" type="audio/mpeg" />
</audio>

Anyway, it's always a good idea to give the user the control to play/stop the music.

OTHER TIPS

Option 1

Use jQuery to your job. call on page load function. Here is code jQuery

Option 2

Use a external plugin to your job. Here is a Wordpress plugin

Option 3

The MSDN way of doing it. Refer this Play audio without audio tag visibility

Hope this helps :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top