1

What is the syntax in html to autoplay ".mp3" files with a loop; automatically when start the web page? I tried with this syntax;

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

this syntax only loop the audio. it will not start the audio automatically

sakun9526
  • 66
  • 5

2 Answers2

1

Alternatively you can try the basic thing to get your need,

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

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

Ashwin Golani
  • 498
  • 3
  • 10
0

You could add a small bit of javascript to auto-play it. Warning: Playing this snippet may be annoying!

var src = "https://www.w3schools.com/HTML/horse.ogg";

function loadaudio(src) {
  var myaudio = document.getElementById("horse");
  myaudio.autoplay = true;
  myaudio.load(src);
};
<body onload="loadaudio();">
<audio id="horse" controls loop>
<source src= "https://www.w3schools.com/HTML/horse.ogg" type="audio/ogg">
</audio>
</body>
Rachel Gallen
  • 27,943
  • 21
  • 72
  • 81