$(audio).bind('timeupdate',function() { if (audio.currentTime >= 26){ var blah = audio.currentTime; audio.currentTime = 23; console.log(blah); } })
这样做很好,但这里唯一的故障是时间更新事件并不会非常一致地触发。例如,上面的console.log返回:
26.14031982421875
26.229642868041992
26.13462257385254
26.21796226501465
…等等。 (你得到的想法…一致的时间)
显然,这对于时间重要的应用程序(音乐应用程序)无效。所以对我来说明显的解决办法是增加触发时间更新事件的粒度。我没有找到任何API文档…但是很想知道是否有办法做到这一点。
解决方法
Every 15 to 250ms,or whenever the MediaController’s media controller position changes,whichever happens least often,the user agent must queue a task to fire a simple event named timeupdate at the MediaController.
也,
The event thus is not to be fired faster than about 66Hz or slower than 4Hz (assuming the event handlers don’t take longer than 250ms to run). User agents are encouraged to vary the frequency of the event based on the system load and the average cost of processing the event each time,so that the UI updates are not any more frequent than the user agent can comfortably handle while decoding the video.
如果您阅读了该规范,您可以得到这样的想法,即timeupdate事件是一种“尽力而为”的事件。它会发射,当它可以,永远只要不影响性能太多。
您可以过滤丢弃某些事件的事件,以平稳到达时间,但恐怕不可能做相反的事情。