0

I am trying to load sounds through the SoundJS sound registration, and getting the following error:

createjs.js:15 Uncaught Error: Type not recognized.

I figure that the soundjs library is having issues either locating my files or having trouble with the file extensions, but I am using .ogg, which is inline with all the examples I've seen.

Here is my code:

createjs.Sound.alternateExtensions = ["mp3", "ogg"];

createjs.Sound.on("fileload", function(event) {
    console.log(event);
}, this);

for (var i = 0; i < soundManifest.length; i++) {
    soundManifest[i].loaded = false;
    console.log("loading " + soundManifest[i].src);
    createjs.Sound.registerSound(soundManifest[i].src, soundManifest[i].id)
}

soundManifest is an array of objects with a source item giving the path to the .ogg files, and an id. I've double and triple checked the path names, so pretty sure that's not it. Any ideas? I am developing on Chrome.

  • Everything in your posted code looks fine (though you don't need to specify "ogg" as an alternate extension if it already has it on the filename you are passing in). Can you provide more info? Do you have a demo that I can check out? What browser(s) is this happening in? Can you show your manifest? – Lanny Apr 19 '16 at 15:46
  • Sure, I just put it up on github: https://github.com/pnob32/chump2020/blob/master/static/js/main.js ... The manifest is declared at line 105 and the concerning code starts at line 180. I really am not sure what is causing this... I have been using chrome, but I will start testing on other browsers. – Patrick Noble Apr 19 '16 at 20:34

1 Answers1

3

Thanks for posting a github link. It was helpful. Fortunately, I have a super simple answer for you.

Rename the "Object" class you made in Main.js, and you should be good to go.

-- The long answer --

I tossed a breakpoint the error that is thrown, and it showed that when SoundJS tries to create a LoadItem, it fails. This is because it should be treating the LoadItem it receives as an Object, but the line below is failing:

} else if (value instanceof Object && value.src) {
    // This code should be executed
}

At first I thought there was a bug in SoundJS that we had somehow missed in the last 2 years, but closer inspection showed that object prototypes in your application are messed up. If you open any browser window, and hit the console, this will return true:

({}) instanceof Object
// true

However while running your app, it returns false.

The issue became clear when I removed all your other classes other than CreateJS and main, and then tried this:

new Object();
// Throws an error that includes info about "Victor"

In main.js, you are defining an "Object" class, which extends a CreateJS Shape. It is global because there is no method closure around the code, so it overwrites the global Object class/prototype.


The reason I included this explanation, is because I couldn't figure out what was going on until I had my steps to show that prototypes were broken in the app mostly written out before the reason dawned on me. I thought it might be of some interest :)

Lanny
  • 11,244
  • 1
  • 22
  • 30