How often does the timeupdate event fire for an html5 video

前端 未结 3 1174
梦谈多话
梦谈多话 2020-11-30 11:32

Learning html5 stuff. It\'s pretty awesome! Wondering how often the timeupdate event fires.

SIDE NOTE: There are so many interesting possibilities with the js video

3条回答
  •  臣服心动
    2020-11-30 12:07

    If you only need to run a function every so often it'd be a better idea to run it using the play and pause events.

    Below is an example of running a process every 3 seconds while the video is playing.

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

提交回复
热议问题