Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 317
Peeyush Avatar asked Aug 01 '11 09:08

Peeyush


People also ask

How do you call a function inside a HTML tag?

Step 1: Firstly, we have to type the script tag between the starting and closing of <head> tag just after the title tag. And then, type the JavaScript function. Step 2: After then, we have to call the javaScript function in the Html code for displaying the information or data on the web page.

How do you call a function in a hyperlink?

Call JavaScript on Hyperlink ClickAdd below HREF html code in body section and access on web browser. Now just click link, It will execute JavaScript's myFunction which will show current date as per used above.

What is function calling in JavaScript?

The Function call is a predefined javascript method, which is used to write methods for different objects. It calls the method, taking the owner object as an argument. The keyword this refers to the “owner” of the function or the object it belongs to. All the functions in javascript are considered object methods.


1 Answers

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);
like image 190
Semyazas Avatar answered Oct 18 '22 20:10

Semyazas