I’m used to creating sounds like this:
NSString *explosionsoundpath = [[NSBundle mainBundle] pathForResource:@"explosion" ofType:@"caf"];
CFURLRef explosionurl = (CFURLRef ) [NSURL fileURLWithPath:explosionsoundpath];
AudioServicesCreateSystemSoundID (explosionurl, &explosion1a);
AudioServicesCreateSystemSoundID (explosionurl, &explosion1b);
where explosion1a and explosion1b are instance variables declared in the .h file with:
SystemSoundID explosion1a;
Whenever I try to make this process in an array like this
NSString *plasmasoundpath = [[NSBundle mainBundle] pathForResource:@"plasmasound" ofType:@"caf"];
CFURLRef plasmaurl = (CFURLRef ) [NSURL fileURLWithPath:plasmasoundpath];
SystemSoundID plasmalaunch1;
AudioServicesCreateSystemSoundID (plasmaurl, &plasmalaunch1);
[self.plasmasounds addObject:plasmalaunch1];
I get a warning:
"Passing argument 1 of addObject makes pointer from integer without a cast.
If I put the & symbol before plasmalaunch1 in the addObject argument I get an
incompatible pointer type warning.
I’m trying to create an array of sound effects which I can later play by calling:
SystemSoundID sound = [self.plasmasounds objectAtIndex:i];
AudioServicesPlaySystemSound(sound);
Advice on how to make this work (or a better way to solve this problem) appreciated!
A SystemSoundID is a integer value, not an object; and a pointer to a number is not a pointer to an object.
You could encapsulate the numeric value in an object before storing it in an NSArray, and then later removing the ID number from the object to play the sound. Or you could store the integer value in a C array instead of an NSArray.