HTML5音频事件触发没有在Chrome [英] HTML5 Audio events not triggering on Chrome

查看:307
本文介绍了HTML5音频事件触发没有在Chrome的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想有一个加载进度条在我的游戏,我有一个分配给我的音频onloadeddata属性的功能,但它不能在Chrome中触发。它工作在其他浏览器。我也试过很多其他活动,如oncanplay,oncanplaythrough,onloadedmetadata等,他们都没有触发。

I'm trying to have a load progress bar in my game, and I have a function assigned to the onloadeddata attribute on my audio, but it is not triggering in Chrome. It works in other browsers. I also tried many other events such as oncanplay, oncanplaythrough, onloadedmetadata, etc. None of them trigger.

我想可能有缓存做。试着环顾四周,有2-3年前,但这样一些报道最近没什么

I think it might have to do with the caching. Tried looking around and there was some reports of this from 2-3 years ago but nothing recent.

有没有我可以检测是否音频被加载,或使这些事件工作的任何其他方式?

Is there any other way I could detect if the audio is loaded, or make these events work?

编辑:下面是一个简单的例子: http://jsfiddle.net/3vxCu/1/
工程在Opera和Firefox,但不是在Chrome。它应该给一个警报声时,如果加载完成。

Here's a quick example: http://jsfiddle.net/3vxCu/1/ Works in opera and firefox, but not in Chrome. It should give an alert when sound if finished loading.

推荐答案

看来, onloadeddata 属性不会出于某种原因。但通过的addEventListener 附加一个事件处理程序(或通过jQuery)工作原理:的http:// jsfiddle.net/3vxCu/4/

It seems that the onloadeddata property does not work for some reason. But attaching an event handler through addEventListener (or via jQuery) works: http://jsfiddle.net/3vxCu/4/

bgSound = new Audio();
bgSound.src = "http://www.ehsankia.com/hawkthorne/audio/level.ogg";
bgSound.preload = "auto";
// Standard browsers (not IE before version 9):
// bgSound.addEventListener("loadeddata", testFunction, false);

// jQuery:
$(bgSound).on("loadeddata", testFunction);

function testFunction () {
    alert("Data loaded");
}

这篇关于HTML5音频事件触发没有在Chrome的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆