Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pause a video after a certain time? video.js

I've been messing with video.js whilst learning javascript but can't seem to figure out how to make the video pause after a certain time has passed.

myPlayer.play(function(){
    whereYouAt = myPlayer.currentTime();
    if (whereYouAt == 10) {
        myPlayer.pause();
    }
})

That is my pause code.

like image 432
xiimoss Avatar asked Mar 16 '23 23:03

xiimoss


1 Answers

Check the currentTime in the timeupdate event callback:

var pausetime = 2; // stop at 2 seconds

var myPlayer = videojs('example_video_1');

myPlayer.on('timeupdate', function(e) {
    if (myPlayer.currentTime() >= pausetime) {
        myPlayer.pause();
    }
});

myPlayer.play();

JSFiddle demo: http://jsfiddle.net/EdjxN/17/

like image 105
Miguel Mota Avatar answered Mar 29 '23 23:03

Miguel Mota