最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to pause a video after a certain time? video.js - Stack Overflow

programmeradmin2浏览0评论

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/

发布评论

评论列表(0)

  1. 暂无评论