cannot create a sound with ID of zero
If you call createSound({id: 0, ...}) the sound will not be created. Note the ID of zero. Why would you create a sound with an ID of zero? For me, it was because I was looping through an array of soundfiles and 0 was the index of the first sound. It seems like a suitable ID number. This took me a long time to debug!
There are a few options for a solution. Fix the code so that it can handle an ID of zero. If that's too hard simply throw an exception if _tO.id === 0
ps. thanks for a great piece of open source software. I've been using sound manager for quite a while and have not had to submit an issue until now :)
There are a few options for a solution. Fix the code so that it can handle an ID of zero. If that's too hard simply throw an exception if _tO.id === 0
ps. thanks for a great piece of open source software. I've been using sound manager for quite a while and have not had to submit an issue until now :)
1
person has this problem
I have this problem, too!
Tell me when someone solves it.
The more people who report this problem, the more it gets noticed.
The more people who report this problem, the more it gets noticed.
The company marked this problem solved.
The best solutions from the company
-
SoundManager v2.95a.20090717 is out, and now includes a check for IDs which are a number or a string starting with a digit; it writes a warning to the console if it finds one. Yay!
The company says
this solves the problem
-
To be conservative (and not break stuff), I'm going to introduce the ID check within createSound() as a warning at first - just in case people are using numeric IDs and calling play('0') etc., which should still work fine in that particular case. (More technical developers who see and read debug/console output should notice the warning.)
The company says
this solves the problem
-
Sound IDs are used as part of name/value pairs in an array, so there are a few rules as with standard JS object names.
Namely, sound IDs must be a string which starts with a non-numeric alphabetic character, and reserved JS keywords cannot be used. This is to allow nice syntax eg. soundManager.sounds.mySound.play() and so on.
If you want to generate a bunch of sounds algorithmically, I recommend a simple prefix eg.
for (var i=0; i<soundURLs.length; i++) {
soundManager.createSound({
id: 'mySound'+i,
url: soundURLs[i]
})
};
Because these are stored in an array object, you also can't use reserved keywords - for example, a sound ID of "join". This is a shortcoming of my choice to use an array for storing the objects, but even using a {} structure instead of [] would still have a few reserved cases.
I'm glad SM2 has been useful to you, and mostly not-buggy! :D
I’m happy
The company says
this solves the problem
Create a customer community for your own organization
Plans starting at $19/month
-
Inappropriate?Sound IDs are used as part of name/value pairs in an array, so there are a few rules as with standard JS object names.
Namely, sound IDs must be a string which starts with a non-numeric alphabetic character, and reserved JS keywords cannot be used. This is to allow nice syntax eg. soundManager.sounds.mySound.play() and so on.
If you want to generate a bunch of sounds algorithmically, I recommend a simple prefix eg.
for (var i=0; i<soundURLs.length; i++) {
soundManager.createSound({
id: 'mySound'+i,
url: soundURLs[i]
})
};
Because these are stored in an array object, you also can't use reserved keywords - for example, a sound ID of "join". This is a shortcoming of my choice to use an array for storing the objects, but even using a {} structure instead of [] would still have a few reserved cases.
I'm glad SM2 has been useful to you, and mostly not-buggy! :D
I’m happy
The company says
this solves the problem
-
Inappropriate?I previously had a similar issue with soundmanager and found that if you turn your id into a string like so:
for (var i = 0; i < array.length; i++)
soundManager.createSound({id: i+"", ...});
then it creates the value into the object part of the list instead of the array, and will accept any value.
In essence this way you get a hashtable instead of an array.
There are 2 issues I know of using it this way...
The first: you can't use the
soundManager.sounds.0.play()
syntax.
However, instead you CAN use
soundManager.sounds["0"].play()
The other issue is that if you try to use
soundmanager.sounds.length
then it will never show the correct number of sounds, however since you obviously already have an array of sounds then I wouldn't think that this will matter that much.
I’m confident
-
I would like to note however that using the prefixes results in the same, but the first issue won't exist, so it's probably better if you do it that way if you use the prefix method as it's a bit safer regardless. -
Inappropriate?Thanks for the info and the fix. This was definitely user error on my part. However, I'd suggest failing early with a simple check if _t0.id === 0 then throwing an Error because otherwise everything fails silently and is harder to debug.
I’m thankful
-
I think few people attempt to create sounds with entirely-numeric IDs, though I have had a report or two previously where people have hit issues with IDs that turned out to be reserved keywords in JS. This is something many JS libraries are prone to, however, so it's a bit of an edge case.
Either way, I can put a simple check in there that looks for an ID that's entirely numeric, and reject it. Not a bad safeguard. The current stuff shouldn't fail because it would assign the result to sounds[0], which is valid, but will overwrite any previously-existing sound object at [0]. -
Inappropriate?To be conservative (and not break stuff), I'm going to introduce the ID check within createSound() as a warning at first - just in case people are using numeric IDs and calling play('0') etc., which should still work fine in that particular case. (More technical developers who see and read debug/console output should notice the warning.)
The company says
this solves the problem
-
Inappropriate?ah, yes, making it a warning is an excellent idea. I hadn't thought of that. This solves the problem nicely.
I’m happy
-
Inappropriate?SoundManager v2.95a.20090717 is out, and now includes a check for IDs which are a number or a string starting with a digit; it writes a warning to the console if it finds one. Yay!
The company says
this solves the problem
Loading Profile...



EMPLOYEE
