0

So I have a very simple code which worked yesterday. I get back on the computer this morning and it looks like it does not work anymore.

What I checked:

  • Whether or not my function runs onload (it does)
  • If the path for the audio file is correct (it is)
  • I tried putting the src directly in the audio tag (and deleting the onload call just to make sure). It still does not work.

The code:

HTML:

<body onload="startMusic()">
    <audio id="audio" autoplay loop>
        Your browser does not support HTML5 audio.
    </audio>

<!--rest of the page-->

JS:

const audio = document.getElementById("audio");

function startMusic(){
    audio.src = "./audio/myFile.mp3";
}

I don't have any console error.

Thank you for your time.

DigitalDW
  • 1
  • 2
  • try interacting with your page, for instance add `onclick = startMusic` in your JS and click anywhere. – Kaiido Apr 25 '19 at 08:52
  • Found a workaround [here](https://stackoverflow.com/questions/50490304/how-to-make-audio-autoplay-on-chrome) – DigitalDW Apr 25 '19 at 08:53

0 Answers0