Note: AudioSprite is not a class, but its usage is easily lost in the documentation, so it has been called out here for quick reference.
Audio sprites are much like CSS sprites or image sprite sheets: multiple audio assets grouped into a single file. Audio sprites work around limitations in certain browsers, where only a single sound can be loaded and played at a time. We recommend at least 300ms of silence between audio clips to deal with HTML audio tag inaccuracy, and to prevent accidentally playing bits of the neighbouring clips.
Benefits of Audio Sprites:
Drawbacks of Audio Sprites
canplaythrough event to determine if the audio is loaded. Since audio sprites must jump ahead to play specific
sounds, the audio may not yet have downloaded fully. createjs.Sound.initializeDefaultPlugins();
var assetsPath = "./assets/";
var sounds = [{
src:"MyAudioSprite.ogg", data: {
audioSprite: [
{id:"sound1", startTime:0, duration:500},
{id:"sound2", startTime:1000, duration:400},
{id:"sound3", startTime:1700, duration: 1000}
]}
}
];
createjs.Sound.alternateExtensions = ["mp3"];
createjs.Sound.on("fileload", loadSound);
createjs.Sound.registerSounds(sounds, assetsPath);
// after load is complete
createjs.Sound.play("sound2");
You can also create audio sprites on the fly by setting the startTime and duration when creating an new AbstractSoundInstance.
createjs.Sound.play("MyAudioSprite", {startTime: 1000, duration: 400});
The excellent CreateJS community has created a tool to create audio sprites, available at https://github.com/tonistiigi/audiosprite , as well as a jsfiddle to convert the output to SoundJS format.