I'm having trouble adding NSsound
instances into an NSMutableArray
The error I get is that I cannot do [soundFiles addObject:soundObj]
, because soundObj
is nil
. But if I do [soundObj play]
, it will play - so it is an instance.
//Name of all the sounds to load in.
sounds = [NSArray arrayWithObjects:
@"sound1",
@"sound2",
nil];
for (int i = 0; i < sounds.count; i++) {
NSString *soundName = [NSString stringWithString:sounds[i]];
NSSound *soundObj = [NSSound soundNamed:soundName];
[soundFiles addObject:soundObj];
}
If I change [soundFiles addObject:soundObj]
to [soundFiles addObject:soundName]
it is fine, so it is something with trying to pass the NSSound
I'm hoping to be able to preload a bunch of very short sounds to make them play the minute they are called. milliseconds matter for this project.
I was hoping this would allow me to do [[soundFiles objectAtIndex:1] play]
- as I was thinking that would result it being faster than creating the NSSound
object when it is time to play it.