html5视频的时间更新事件多久触发一次

How often does the timeupdate event fire for an html5 video

本文关键字:一次 视频 时间 更新 事件 html5      更新时间:2023-09-26

学习html5的东西。太棒了!想知道时间更新事件多久触发一次。

旁注:js视频api有很多有趣的可能性。例如,可以使用ctrl+F搜索视频。作为视频处理的一部分运行语音识别,然后创建一个以时间戳为键、以单词为值的长键值存储,并编写一个函数来搜索这些单词的实例,但返回时间戳并查找视频。无论如何,这只是youtube应该接受的一个疯狂想法。

任何关于时间更新的帮助都会很棒!

根据这个Bugzilla页面:

Firefox每帧触发一次时间更新事件。Safari 5和Chrome 6每250毫秒启动一次。Opera每200毫秒发射10.50次。

我使用了一个通用的油门函数

_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/

如果您只需要每隔一段时间运行一个函数,那么最好使用播放和暂停事件来运行它。

以下是在播放视频时每3秒运行一次进程的示例。

video.addEventListener('play', () => {
  video._updateInterval = setInterval(() => {
    // do what you need
  }, 3000);
}, true);
video.addEventListener('pause', () => clearInterval(video._updateInterval), true);