Skip to main content
floras43291626
New Participant
July 20, 2018
Answered

How to do i loop my sound in javascript/html output?

  • July 20, 2018
  • 1 reply
  • 4384 views

I'm publishing my animate file as Javasript/HTML and have the code below. How would I amend this to allow my sound file to loop? Everything plays at the moment apart from looping. Thanks.

_main = this;

this.stop();

createjs.Sound.on("fileload", handleFileLoad);

createjs.Sound.registerSound("sounds/soundtrack.mp3", "MySound");

function handleFileLoad()

{

    _main.audio1 = createjs.Sound.play("MySound"); 

    _main.play(); 

}

This topic has been closed for replies.
Correct answer ankushr40215001

Hey floras,

Please try the below code which I got from GIT and has worked for me too.

createjs.Sound.on("fileload", handleLoad);
createjs.Sound.registerSound("sounds/youraudio.mp3", "myID", 3);
function handleLoad(event) {
createjs.Sound.play("myID");
  // store off AbstractSoundInstance for controlling
  var myInstance = createjs.Sound.play("myID", {interrupt: createjs.Sound.INTERRUPT_ANY, loop:-1});
}

I am also just a beginner in Js coding and hopefully it should work for you also.

Thanks!

Ankush

1 reply

ankushr40215001
ankushr40215001Correct answer
Inspiring
July 20, 2018

Hey floras,

Please try the below code which I got from GIT and has worked for me too.

createjs.Sound.on("fileload", handleLoad);
createjs.Sound.registerSound("sounds/youraudio.mp3", "myID", 3);
function handleLoad(event) {
createjs.Sound.play("myID");
  // store off AbstractSoundInstance for controlling
  var myInstance = createjs.Sound.play("myID", {interrupt: createjs.Sound.INTERRUPT_ANY, loop:-1});
}

I am also just a beginner in Js coding and hopefully it should work for you also.

Thanks!

Ankush

floras43291626
New Participant
July 20, 2018

This seems to have worked. Many thanks!

avid_body16B8
Brainiac
July 20, 2018

This is what I use which is compact.

this.myMusic = createjs.Sound.play("music", "none", 0, 0, -1, 0.5);

//

music is the instance name

"none' is the interrupt

0 is delay

0 is offset

-1 is loop 0 is no loop

0.5 is the volume