Trent
Trent

Reputation: 11

How do i make my Audio loop in my website?

Here is my code:

<div id="div6" style="position: absolute; top: 700px; left: 100px;"> <audio controls="controls; loop:true"> <source src="../media/ChealseSmile.ogg" type="audio/ogg"/> <source src="song.mp3" type="audio/mpeg"/> Your browser does not support the audio element. </audio> </div>

What do i have to add to the audio code to make it loop or autostart?

As a bonus, could someone also tell me how to make a playlist out of this code?

Upvotes: 1

Views: 643

Answers (2)

OmegaNine
OmegaNine

Reputation: 371

<audio loop id="music" controls autoplay="autoplay">
   <source src="music.oog" type="audio/ogg">
   <source src="music.mp3" type="audio/mpeg">
   <embed height="2" width="2" src="engine1/granadosorienta_pianol.mp3">
</audio>

Then you can add this JS for old FF browsers if you want to support them

<!--- Fix the FF Audio Loop bug --!>
  document.getElementById('music').addEventListener('ended', function(){
  this.currentTime = 0;
  this.play();
}, false);

Upvotes: 0

Aaron Saunders
Aaron Saunders

Reputation: 33345

<audio loop="loop" /> 

Upvotes: 2

Related Questions