Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ended event videojs not working

I would like to trigger a simple event when my video is finished. I've placed this directly bellow my video tag.

     <script type="text/javascript">
        var myPlayer = videojs("session_video");
          videojs("session_video").ready(function(){
          this.addEvent("ended", function(){ 
            alert('Here I am');
          });
        });       
     </script>

However I get: TypeError: this.addEvent is not a function and I can't find why.

You can see it live here: 78.47.121.50 (stackoverflow won't allow to make that a link) enter code 01-01-01-2012 to bring up the video.

Any insight is much apricaited!

Kind regards, Jason.

like image 482
Jason Schot Avatar asked May 15 '13 20:05

Jason Schot


2 Answers

"addEvent" and "removeEvent" were replaced by "on" and "off"

try:

this.on("ended", function(){ 
like image 121
Lyn Headley Avatar answered Sep 20 '22 15:09

Lyn Headley


For those who still have problems with ended events in some browsers you can resort to this fix:

    player.ready(function() {
            var myPlayer = this;

            playerInstance.on("timeupdate", function(event) { //chrome fix
                if (event.currentTarget.currentTime == event.currentTarget.duration) {
                    console.log('video ended');
                }
            });
    });
like image 33
Dziamid Avatar answered Sep 16 '22 15:09

Dziamid