miasweb
miasweb

Reputation: 23

Reloading page when audio ends

I'm trying to have a web page automatically reload itself when an audio file has stopped playing. I've tried playing around with the tag w/ the onended parameter to no avail. Please help.

<html>
<body>
<center>
<embed src="1.wav" width="0" height="0"></embed>
</center>
</body>
</html>

Upvotes: 0

Views: 103

Answers (2)

Kamiccolo
Kamiccolo

Reputation: 8497

First of all, as pawel mentioned, You should use <audio> tag instead.

Then You could do something like that using media events and JS.

It might look like this:

var audio_element = document.getElementsByTagName("audio")[0];
audio_element.addEventListener("ended",
    function() {
      document.location.reload(true); 
    }, true);

Bare in mind, there are better ways for changing or looping audio file.

Upvotes: 0

pawel
pawel

Reputation: 36965

You should use <audio /> element and its ended event.

<audio src="1.wav" onended="window.location.reload()" />

Audio element on MDN

Media events on MDN

Demo

BTW if you want to reload just so it loops then... there are better ways to do it. If you want to play a random track on each load it could also be done without reloading the page.

Upvotes: 3

Related Questions