HTML5 Audio Looping

Viewed 153875

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();

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.

10 Answers

Everyone knows now if you type:

<audio controls="controls" loop="loop">
    <source src="someSound.ogg" type="audio/ogg" />
</audio>

It will play the song and it will be looping But there is a shorter way to play the song continuously:

<audio controls loop src="someSound.ogg"></audio>
Related