Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/407.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在html5视频中允许倒带但禁用快进_Javascript_Html5 Video - Fatal编程技术网

Javascript 如何在html5视频中允许倒带但禁用快进

Javascript 如何在html5视频中允许倒带但禁用快进,javascript,html5-video,Javascript,Html5 Video,我有以下代码(使用videojs) 问题是,一旦您尝试快进一次,它就不再跟踪进度条上的时间更新。我再也不能在吧台上寻找——甚至连视频都不能倒带。这里我遗漏了什么?首先,这些不是标准的HTMLMediaElement方法和属性,所以我假设您正在使用某种框架,也许?我假设这个指的是包装视频元素的对象 问题是您正在覆盖currentTime方法。如果要直接引用视频元素,则可以通过设置currentTime属性,如:videoElement.currentTime=previousTime,来查找执行方

我有以下代码(使用videojs)


问题是,一旦您尝试快进一次,它就不再跟踪进度条上的时间更新。我再也不能在吧台上寻找——甚至连视频都不能倒带。这里我遗漏了什么?

首先,这些不是标准的HTMLMediaElement方法和属性,所以我假设您正在使用某种框架,也许?我假设
这个
指的是包装视频元素的对象

问题是您正在覆盖
currentTime
方法。如果要直接引用视频元素,则可以通过设置
currentTime
属性,如:
videoElement.currentTime=previousTime
,来查找执行方法。但是由于您使用的是框架,
this.currentTime
应该是一个函数,直到您将其更改为数字

要演示,请按如下方式修改代码:

this.on("seeking", function(){
    console.log(typeof this.currentTime); // 'function'
    if (this.currentTime() > previousTime){
        this.currentTime = previousTime;
        console.log(typeof this.currentTime); // 'number'
    }
});
下次运行“timeupdate”处理程序时,对
this.currentTime()
的调用将抛出一个错误,因为它不再是函数

您可能可以这样修复它(假设您使用的是爆米花或类似的东西):

您还需要确保在搜索时不设置
previousTime
,因为“timeupdate”可能会在“seek”之前触发。我不知道如何使用您的框架实现这一点,因此这里有一个链接,指向使用本机HTMLVideoElement API的工作示例:


首先,这些不是标准的HTMLMediaElement方法和属性,所以我假设您正在使用某种框架,也许?我假设
这个
指的是包装视频元素的对象

问题是您正在覆盖
currentTime
方法。如果要直接引用视频元素,则可以通过设置
currentTime
属性,如:
videoElement.currentTime=previousTime
,来查找执行方法。但是由于您使用的是框架,
this.currentTime
应该是一个函数,直到您将其更改为数字

要演示,请按如下方式修改代码:

this.on("seeking", function(){
    console.log(typeof this.currentTime); // 'function'
    if (this.currentTime() > previousTime){
        this.currentTime = previousTime;
        console.log(typeof this.currentTime); // 'number'
    }
});
下次运行“timeupdate”处理程序时,对
this.currentTime()
的调用将抛出一个错误,因为它不再是函数

您可能可以这样修复它(假设您使用的是爆米花或类似的东西):

您还需要确保在搜索时不设置
previousTime
,因为“timeupdate”可能会在“seek”之前触发。我不知道如何使用您的框架实现这一点,因此这里有一个链接,指向使用本机HTMLVideoElement API的工作示例:


是的,我正在使用videojs。。。哇,为什么我没提到。。。抱歉编辑了它。。。是的,我真不敢相信这么小的变化怎么会有这么大的不同。。。塔克斯!是的,我用的是videojs。。。哇,为什么我没提到。。。抱歉编辑了它。。。是的,我真不敢相信这么小的变化怎么会有这么大的不同。。。塔克斯!
this.on("seeking", function(){
    if (this.currentTime() > previousTime){
        this.currentTime(previousTime);
    }
});