Check audio is playing

Hi all, hopefully my last post for this project, I just need to enable an audio check loop that enables my audio to play all the way through before redirecting to a new page. this is my script so far:

<script>
function notrust() {
	var audio = new Audio('voices/notrust.mp3');
        audio.play();    
        setTimeout(audiocheck, 10);
		}
function audiocheck() {
        if (audio.isPlaying == false) {
        setTimeout(redirect, 10);
		} else if (audio.isPlaying == true) {
		    setTimeout("audiocheck()",500);
	   } else {
       }
}
function redirect() {
        window.location.replace("http://www.google.com");
}
</script>

any help would be appreciated :slight_smile:

Cheers!

Hi there aaron51connelly,

have you not considered simply using something like this…

   audio.addEventListener( 'ended', 
     function(){
         location.href = 'https:www.google.com';
      }, false );

coothead

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.