SPARKST3R3556
SPARKST3R3556

Reputation: 21

How to autoplay music with <audio> tags (NOT with <audio autoplay>)

<!DOCTYPE html>
<html>
<body>

<audio id="myAudio">
<source src="punch-high1.mp3" type="audio/mpeg">
</audio>

<script>
var x = document.getElementById("myAudio");

x.loop = true;
x.autoplay = true;
x.load();

</script> 
</body>
</html>

This is the code I'm currently using to test out Autoplay with the audio tags. But it's not working, I have tested it with the horse.mp3 from w3schools and made it match this code EXACTLY how it is, but this code still doesn't work while the code from w3schools that I modified does. And I have tried using autoplay within the first audio tag but it doesn't work.

Upvotes: 2

Views: 129

Answers (1)

Srishti Gupta
Srishti Gupta

Reputation: 1273

After Chrome 66 update, you need to manually change your Chrome settings so that the autoplay works.

Steps to follow:

  1. Type chrome://flags/#autoplay-policy in the URL
  2. In the dropdown, select "No user gesture is required".
  3. Relaunch Chrome.

P.S.: You do not require x.load() statement in your code.

Upvotes: 1

Related Questions