0

Trying to get a button to refresh the page only after the sound stops playing. I have tried the onend event but without success.

function play() {
  var audio = document.getElementById("audio");
  audio.play();
}

function myFunction() {
  location.reload(1);
}
<button onclick="myFunction()">Reload page</button>

<img src="./images/play.png" value="PLAY" onclick="myFunction();play()">
<audio id="audio" src="./Sounds/Casino4.wav"></audio>

Play button currently only refreshes the page but you can hear the sound starting, but the page refreshes before it stops.

Alex Michailidis
  • 4,078
  • 1
  • 16
  • 35
  • 2
    Possible duplicate of [How to detect an audio has finished playing in a web page?](https://stackoverflow.com/questions/4619917/how-to-detect-an-audio-has-finished-playing-in-a-web-page) – weegee Feb 10 '19 at 19:53

1 Answers1

0

try

var audio = document.getElementById("audio");
audio.onended = function() {
    // Your function here
}; 

The ended event occurs when the audio/video has reached the end. >> https://www.w3schools.com/tags/av_event_ended.asp