-1

I am using a very basic HTML5 audio script and I would simply like the song to loop. How can I accomplish this? Thanks in advance!

$(".play").click(function(){
    var snd = new Audio("bells.mp3");
    snd.play();
});
APAD1
  • 13,509
  • 8
  • 43
  • 72
  • http://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_audio_loop Here's one example. – Lauri Elias Dec 16 '13 at 21:58
  • Sorry for the duplicate, searched SO but didn't see that one. – APAD1 Dec 16 '13 at 22:03
  • 1
    @APAD1 no problem, I just happened to remember it existed and wanted to make sure you saw that `loop` hasn't always worked in case you want to support legacy browsers. – Dagg Nabbit Dec 16 '13 at 22:05

2 Answers2

1

Specify the loop attribute in your HTML mark-up

<audio loop>
   <source src="bells.mp3" type="audio/mpeg">
<audio>

No JavaScript needed

Lloyd Banks
  • 35,740
  • 58
  • 156
  • 248
0

Set the loop property to true

$(".play").click(function(){
    var snd = new Audio("bells.mp3");
    snd.loop = true;
    snd.play();
});