Search code examples
canvasjquery-animatecreatejseaseljsadobe-animate

Is it possible to loop this createjs.sound?


I've used this script to make it possible to turn on and off my audio. However, as I don't have an option to click and loop my song on my timeline. When this song ends, it doesn't play again.

I would like to know if I can add something to this script to make my song loop after it ends.

I've found this and have tried ...

createjs.Sound.play("soundId", {loop:-1});

But it doesn't work!

I'm working on html5 canvas on Adobe Animate!

I'm using this script, it works:

createjs.Sound.on("fileload", function handleLoad(event) {
    root.audio = createjs.Sound.play("soundID");
});

createjs.Sound.registerSound("sounds/myaudio.mp3", "soundID");  

//this.audio1.paused = true; // pause     
//this.audio1.paused = false; // resume 

this.onOff_btn.on("click", function(){
    if(root.audio.paused) {
        root.audio.paused = false; // resume
    } else {
        root.audio.paused = true; // pause
    }
});

Thank you in advance!


Solution

  • If anyone is wondering how to do this, I found a way to make it work!

    Here it is:

    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});
     }
    
     //this.audio1.paused = true; // pause     
    //this.audio1.paused = false; // resume 
    
    this.onOff_btn.on("click", function (evt) {
            v = createjs.Sound.getVolume();
            if (v < 0.5) {
                createjs.Sound.setVolume(1);
            } else {
                createjs.Sound.setVolume(0);
            }
        });
    

    It loads your audio, loops it and has a button on which you click to make it play or pause! Thanks to everyone who have tried to help!