给定秒的视频事件 [英] Video event on given second

查看:127
本文介绍了给定秒的视频事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前视频时间达到给定值时,需要播放下一个视频,但不知道为什么应该获取currentTime的事件根本不会被触发?也许有人知道为什么(显然最简单的任务是造成大多数问题的任务)

Need to play the next video, when current video time reaches the given value, but don't know why the event that should get currentTime is not firing at all? Maybe someone has an idea why (obviously the simplest tasks are the ones making most problems)

   function setupVideoPlayer() { 
var currentVideo = 1;
// i.e. [video url, start time, end time]
var videos = [["1.mp4", 0, 4], ["2.mp4", 3, 7]];
var videoPlayer = document.getElementById('videoPlayer');
// set first video clip
videoPlayer.src = videos[0][0]; // 1.mp4
// Syncrhonization function should come here


videoPlayer.addEventListener('timeupdate', function(e){
    if (this.currentTime == videos[currentVideo-1][2]) {
        currentVideo += 1;
        this.src = videos[currentVideo-1][0];
        this.play();
    }
}, true);

// It makes sure the seek will happen after buffering 
// the video
videoPlayer.addEventListener('progress', function(e) {
    // Seek to start point
    this.currentTime = videos[currentVideo-1][1]; 
}, false)
}


推荐答案

我建议将时间检查更改为>而不是=因为currentTime事件不是积分器

I would suggest changing the time check to a > rather than = because the currentTime event isn't an integrer

if (this.currentTime == videos[currentVideo-1][2]) {

变为

if (this.currentTime > videos[currentVideo-1][2]) {

(或者您可以将其转换为集成商测试)

(or you could convert it to an integrer for the test)

如果还有其他问题,值得为活动添加 console.log(this.currentTime)只是为了看它是否触发了代码

If there are other issues it's worth adding a console.log(this.currentTime) to the event just to see if it's triggering the code

这篇关于给定秒的视频事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆