设置HTML5音频事件’timeupdate’的粒度

我正在尝试使用HTML5音频创建一个简单的循环功能,并具有非常原始的解决方案如下:
$(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文档…但是很想知道是否有办法做到这一点。

解决方法

我很抱歉,但这是它的工作方式。从 html5 specs

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事件是一种“尽力而为”的事件。它会发射,当它可以,永远只要不影响性能太多。

您可以过滤丢弃某些事件的事件,以平稳到达时间,但恐怕不可能做相反的事情。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


HTML5和CSS3实现3D展示商品信息的代码
利用HTML5中的Canvas绘制笑脸的代码
Html5剪切板功能的实现
如何通过HTML5触摸事件实现移动端简易进度条
Html5移动端获奖无缝滚动动画实现
关于HTML5和CSS3实现机器猫的代码
HTML5使用DOM进行自定义控制
使用HTML5 Canvas绘制阴影效果的方法
使用PHP和HTML5 FormData实现无刷新文件上传
如何解决HTML5 虚拟键盘出现挡住输入框的问题
HTML5中div和section以及article的区别分析
html5和CSS 实现禁止IOS长按复制粘贴功能
html5 touch事件实现触屏页面上下滑动
canvas 模拟实现电子彩票刮刮乐的代码
HTML5 Plus 实现手机APP拍照或相册选择图片上传的功能
Android自定义环形LoadingView效果
HTML5 canvas绘制五角星的方法
html5使用html2canvas实现浏览器截图
使用Canvas处理图片的方法介绍
利用Canvas模仿百度贴吧客户端loading小球的方法