0

I would like to play a sound on a load of an HTML page. First I tried this solution:

<audio src="static/audio/lang/pchwcafckzdmfcvuneezavatquflye_en.mp4" id="my_audio" loop="loop" type="audio/mpeg"></audio>
<script type="text/javascript">
    window.onload=function(){
    document.getElementById("my_audio").play();
    }
</script>

It did not work. Then I have tried this one:

<audio src="static/audio/lang/pchwcafckzdmfcvuneezavatquflye_en.mp4" id="my_audio" loop="loop" type="audio/mpeg"></audio>
<script type="text/javascript">
var sample = document.getElementById("my_audio");
sample.play();
</script>

This does not work as well. In have tried to load the page in Chrome as well as Firefox. In both browsers if does not work.

What am I doing wrong?

Roman
  • 124,451
  • 167
  • 349
  • 456

1 Answers1

1

Autoplay with sound is disabled and policies updated in Chrome and Firefox

Check these articles:

pr96
  • 994
  • 5
  • 17