javascriptaudiocreatejssoundjspreloadjs

PreloadJS cannot find audio


I'm working on hobby project. I'm using createjs. But, of course, I have a problem. Since I update the code to use Preloadjs, the browser can no longer find the audio files. Here is my loading code:

function load (canvasToShowProgress) {
    canvas = canvasToShowProgress;
    loadingStage = new createjs.Stage();
    loadQueue = new createjs.LoadQueue(true);
    progessText = new createjs.Text("Loading... 0%");
    loadingStage.addChild(loadingStage);
    loadingStage.update();

    //start loading
    loadQueue.installPlugin(createjs.Sound);
    loadQueue.setMaxConnections(4); // Allow 4 concurrent loads
    loadQueue.loadManifest("configuration/GameAssets.json");
    loadQueue.on("progress", handleProgress);
    loadQueue.on("complete",handleComplete);
}

My manifest GameAssets.json looks like this:

{"manifest":
[   {"src":"images/game/street.png", "id":"street"},
    {"id":"Default", "src":"sounds/game/background.ogg"},
    {"id":"Psychic", "src":"sounds/game/ps.ogg"},
    {"id":"Nitro", "src":"sounds/game/ntr.ogg"}
]
}

By the way, the image is loaded perfectly. In the music player class, I call the audio by simply doing soundInstance = createjs.Sound.play(soundIds[currentPlayIndex]);. (The soundIds is temporary a hardcoded array with the ids. Where is my mistake?


Solution

  • First, I just want to confirm you are using the latest 0.6.0 releases of both SoundJS and PreloadJS (they need to be used together).

    Currently only Firefox and Chrome support Ogg, so if you are using another browser you would need to provide and alternate format (mp3 is currently the most broadly supported) and set it up using SoundJS.alternateExtensions.

    If you are still having loading errors, you'd likely need to dig into the errors a little more to determine the cause.

    Hope that helps.