admin管理员组

文章数量:1328030

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.

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.

Share Improve this question asked Feb 18, 2015 at 17:44 xiimossxiimoss 8053 gold badges13 silver badges21 bronze badges 2
  • I think you need to wrap that in a setInterval() in order to check the time more often – Jonas Grumann Commented Feb 18, 2015 at 17:45
  • @xiimoss jsfiddle/EdjxN/17 – Miguel Commented Feb 18, 2015 at 17:59
Add a ment  | 

1 Answer 1

Reset to default 7

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/EdjxN/17/

本文标签: javascriptHow to pause a video after a certain time videojsStack Overflow