I managed to get sounds to work the way I want, but I’m a bit confused how to preload things. I have 2 sound formats:
sounds/myAudioLoop.ogg
sounds/myAudioLoop.mp3
I want to use ogg, but in Animate, I can only insert mp3 to the timeline:
In Frame 1, there’s a this.stop(); and a play button. When the play button gets pressed, it’ll jump to the “start” frame and the sound plays.
In Frame 2 labeled “start”, I added my preload and sound codes:
// preload
var queue = new createjs.LoadQueue();
createjs.Sound.alternateExtensions = ["m4a"];
queue.installPlugin(createjs.Sound);
queue.on("complete", handleComplete);
queue.loadFile({
id: "audioLoop",
src: "sounds/myAudioLoop.ogg"
});
createjs.Sound.on("fileload", handleLoad);
createjs.Sound.alternateExtensions = ["m4a"];
createjs.Sound.registerSound({
id: "audioLoop",
src: "sounds/myAudioLoop.ogg"
});
var _this = this;
function handleLoad(event) {
_this.audioLoopInstance = createjs.Sound.play("audioLoop", {
interrupt: createjs.Sound.INTERRUPT_ANY,
loop: -1
});
};
I read that Animate will always preload stuff, so I didn’t add the mp3 into the preload code. When I test the movie, and press the play button, both formats play, but the ogg lags. I’m guessing it’s because Animate’s preload code runs first, plays the mp3 (cause I added it to the timeline), then runs the preload codes when it gets to Frame 2.
I frankensteined the codes, so I’m not really sure how edit it to make it all work properly.
Is there a way to preload everything without adding the sound to the timeline in Animate?
And for it to play ogg, with mp3 as the fallback for browsers that don’t support ogg?