I managed to make the sound loop start when the frame loads using this code:
createjs.Sound.on("fileload", handleLoad);
createjs.Sound.alternateExtensions = ["m4a"];
createjs.Sound.registerSound({
id: "audioLoop",
src: "sounds/myAudioLoop.ogg"
});
function handleLoad(event) {
var audioLoopInstance = createjs.Sound.play("audioLoop", {
interrupt: createjs.Sound.INTERRUPT_ANY,
loop: -1
});
};
When I try audioLoopInstance.stop(); or audioLoopInstance.play(); though, nothing seem to happen.
The stop all sounds seem to work, although I don't know how to play it again after that:
stopEverySounds = function () {
return createjs.Sound.stop();
}
stopEverySounds();
I am trying to learn to use the sound instance thing. How do I make audioLoopInstance to start the sound again?
Update: Seems I have to define the var in my original code like this:
var _this = this;
function handleLoad(event) {
_this.audioLoopInstance = createjs.Sound.play("audioLoop", {
interrupt: createjs.Sound.INTERRUPT_ANY,
loop: -1
});
};
And then I'll be able to use that sound instance.
If stop/play code is in same frame:
_this.audioLoopInstance.stop();
If stop/play code is in different frame in the same timeline:
this.audioLoopInstance.play();