I am currently using Pixi.js and its built in Loader, as I peeked through the code, I notice I can load sounds as well. I am using different loader for Sound which is specifically built-in as well within SoundJS.
The problem is, I have to manage two different loaders to accomplish this. One for sound and another one texture.
I have my Pixi.js load sound files for me like this:
new PIXI.loaders.Loader()
.add("_assets/textures/p1_walk/Von.json")
.add("_assets/textures/p2_walk/Don.json")
.add("_assets/textures/p3_walk/Bon.json")
.add("_assets/textures/tiles.json")
.add("_assets/textures/textures.json")
//.add('bgm1' , '_assets/bgm/bgm.mp3')
.add('jump' , '_assets/sfx/jump.wav')
.add('pickupcoin' , '_assets/sfx/pickupcoin.wav')
.add('hit' , '_assets/sfx/hit.wav')
.add('hit1' , '_assets/sfx/hit1.wav')
.add('died' , '_assets/sfx/died.wav')
.on("progress" , function(loader , resource)
{
console.log("Finished loading : " + resource.name + " progress : " + loader.progress);
})
.once("complete" , function()
{
console.log("Finished loading assets");
//soundManifest = soundManifest.concat(
// [
// {id : "bgm1" , src : "_assets/bgm/bgm.mp3" }
// , {id : "jump" , src : "_assets/sfx/jump.wav" }
// , {id : "pickupcoin" , src : "_assets/sfx/pickupcoin.wav" }
// , {id : "hit" , src : "_assets/sfx/hit.wav" }
// , {id : "hit1" , src : "_assets/sfx/hit1.wav" }
// , {id : "died" , src : "_assets/sfx/died.wav" }
// ]);
//createjs.Sound.alternateExtensions = ['mp3' , 'ogg' , 'wav' ];
//createjs.Sound.addEventListener('fileload' , handleLoad);
//createjs.Sound.registerSounds(soundManifest);
SoundJS.play("jump");
loadingScene = new LoadingScene(renderer , screenSize);
})
.load();
Unfortunately, this won't work. Jump sound won't play. I don't know how to make SoundJS load/play already loaded sound by a completely different/unrelated loader.
I not sure what to do, how can I manage two separate loaders? The problem with my previous one is that the first loader was able to give me 0-100% progress which I sorely need so that I could use it in my progress bar. But, this is only for texture, I wanted to include Sounds in the percentage and decided maybe I could use only loader and make SoundJS load the files from there.
Is this possible at all?
Thanks!
SoundJS can only play back sounds that have been registered and loaded by SoundJS. It may be possible to register a sound and its loaded data using private APIs, but it would take some work, and there is no official approach.
The key things you have to do:
AbstractPlugin._handlePreloadComplete
method, which stores the loaded ArrayBuffer in the _audioSources
hash.You would have to do that for each sound. Once the sound is registered, and has the necessary data for each ID, the SoundJS APIs should work.
This is an interesting approach, and it might make sense to add it as a feature request to SoundJS.