Lee Ikard
Lee Ikard

Reputation: 76

Automatically play audio in HTML 5

I have music I want to play and loop on the web page startup. Here's my code:

<audio autoplay="autoplay"  loop controls="controls"> 
  <source src="music.mp3" />  
</audio> 

The question that is a "duplicate" does not suit my needs and does not work for me.

Upvotes: 0

Views: 1705

Answers (1)

Lee Ikard
Lee Ikard

Reputation: 76

I found out what to do using a div with the visibility to hidden

<div style="visibility:hidden">
<audio controls autoplay loop>
  <source src="horse.ogg" type="audio/ogg">
  <source src="horse.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
</div>

Upvotes: 1

Related Questions