james
james

Reputation: 2663

Is there an oncomplete event for HTML5 audio?

Is there an oncomplete event for HTML5 audio? I could not find anything on this. I am trying to play a sound after it completes.

Well, specifically I am trying to play through an array of sounds one after the other.

Thanks.

Upvotes: 27

Views: 28913

Answers (2)

the JinX
the JinX

Reputation: 1980

There is the ended event . . .

http://dev.w3.org/html5/spec/Overview.html#event-media-ended

Example:

var audioElement = document.getElementById("myAudio");

audioElement.addEventListener('ended', function() {
    // Audio has ended when this function is executed.
},false);

Upvotes: 32

Tomas Ramirez Sarduy
Tomas Ramirez Sarduy

Reputation: 17471

The correct way to to this is using the addEventListener function:

audio.addEventListener('ended', PlayNext);

Upvotes: 21

Related Questions