How to call a function on video end ? (HTML5 and mediaelementjs)

Peeyush picture Peeyush · Aug 1, 2011 · Viewed 19.7k times · Source

i am using mediaelementjs for playing video on my website but i need to call some

function at the END/pause of video.So please tell me how an i do this?

Thanks in advance

Answer

Semyazas picture Semyazas · Aug 1, 2011

You need to create a new EventListener for the ended and pause events.

Example:

YourMediaElement.addEventListener('ended', function(){
    //Your Code goes here
});

Update: This method should be applied on the success handler of creating the element, as is shown in the example on the bottom of the page at MediaElementJS.com

success: function (YourMediaElement, domObject) { 

    // add event listener
    YourMediaElement.addEventListener('ended', function(e) {

           //Do Stuff here

    }, false);