正在学习HTML5知识,非常棒!想知道timeupdate事件的触发频率。
顺便提一下:JS视频API有很多有趣的可能性。例如,可以使用ctrl + F在视频中搜索。将语音识别作为视频处理的一部分,然后创建一个以时间戳为键、单词为值的长键值存储,并编写一个函数来搜索这些单词的实例,但返回时间戳并定位到视频中。无论如何,这只是一个疯狂的想法,YouTube应该借鉴。
希望能有关于timeupdate的任何帮助!
正在学习HTML5知识,非常棒!想知道timeupdate事件的触发频率。
顺便提一下:JS视频API有很多有趣的可能性。例如,可以使用ctrl + F在视频中搜索。将语音识别作为视频处理的一部分,然后创建一个以时间戳为键、单词为值的长键值存储,并编写一个函数来搜索这些单词的实例,但返回时间戳并定位到视频中。无论如何,这只是一个疯狂的想法,YouTube应该借鉴。
希望能有关于timeupdate的任何帮助!
Firefox每帧触发一次timeupdate事件。Safari 5和Chrome 6每250毫秒触发一次。Opera 10.50每200毫秒触发一次。
video.addEventListener('play', () => {
video._updateInterval = setInterval(() => {
// do what you need
}, 3000);
}, true);
video.addEventListener('pause', () => clearInterval(video._updateInterval), true);
我使用了一个通用的节流函数
_self.throttle = function (fn, threshhold, scope) {
threshhold || (threshhold = 250);
var last,
deferTimer;
return function () {
var context = scope || this;
var now = +new Date,
args = arguments;
if (last && now < last + threshhold) {
// hold on to it
clearTimeout(deferTimer);
deferTimer = setTimeout(function () {
last = now;
fn.apply(context, args);
}, threshhold);
} else {
last = now;
fn.apply(context, args);
}
};
};
并使用有线连接进行了连接
myPlayer.on('timeupdate', window.vm.throttle(function () {
window.vm.setWatched(myPlayer.currentTime());
}, 3000));
希望这能对某些人有所帮助。
代码来自http://remysharp.com/2010/07/21/throttling-function-calls/