HTML5音频循环 [英] HTML5 Audio Looping
问题描述
我最近一直在玩HTML5音频,虽然我可以让它播放声音但它只播放一次。无论我尝试什么(设置属性,事件处理程序等),我似乎无法让它循环。
I've been playing with HTML5 audio recently, and though I can get it to play the sound it only ever will play once. No matter what I try (setting the properties, event handlers, etc) I can't seem to get it to loop.
以下是我使用的基本代码:
Here's the basic code I'm using:
//myAudio is declared at a global scope, so it doesn't get garbage collected.
myAudio = new Audio('someSound.ogg');
myAudio.loop = true;
myAudio.play();
我正在使用Chrome(6.0.466.0 dev)和Firefox(4 beta 1)其中似乎很乐意忽略我的循环请求。任何想法?
I'm testing using Chrome (6.0.466.0 dev) and Firefox (4 beta 1), both of which seem happy to ignore my requests for looping. Any ideas?
UPDATE: The loop property is now supported in all major browsers.
推荐答案
while loop
是指定的,它并不在中实现,我知道的任何浏览器都是Firefox。[感谢Anurag指出这一点] 。这是循环的一种替代方式,可以在支持HTML5的浏览器中使用:
While loop
is specified, it is not implemented in any browser I am aware of Firefox [thanks Anurag for pointing this out]. Here is an alternate way of looping that should work in HTML5 capable browsers:
myAudio = new Audio('someSound.ogg');
myAudio.addEventListener('ended', function() {
this.currentTime = 0;
this.play();
}, false);
myAudio.play();
这篇关于HTML5音频循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!