Reputation: 35
I have a bunch of sound clips, named sound1.mp3 through soundN.mp3. I want to randomly play them on touch, so I've set up an AVAudioPlayer for each clip which are all stored in players (AVAudioPlayer**). After I initialize everything, the only sound I can get to play is sound1.mp3. What am I doing wrong?
Thanks for the help, init code is below.
players = (AVAudioPlayer**) malloc ( sizeof (AVAudioPlayer*) * NUM_CLIPS);
NSString* path;
NSString* name;
for(uint i = 0; i < NUM_CLIPS; i++){
name = [NSString stringWithFormat: @"sound%d", i+1];
path = [[NSBundle mainBundle] pathForResource:name ofType:@"mp3"];
players[i] = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
[players[i] setMeteringEnabled:YES];
[players[i] prepareToPlay];
}
Upvotes: 0
Views: 919
Reputation: 21
James Brooks (jamesbrooks dot net) says that changing the *.mp3 files into *.caf allowed him to play multiple sounds with the AVAudioPlayer. I personally, however, can not get the *.caf files to play at the same time but I can get *.aiff files to play simultaneously.
Upvotes: 0
Reputation: 25256
The reason for this is that mp3/aac files are hardware decoded and only on at a time can be decoded.
Upvotes: 2
Reputation: 35
Nevermind, seems like it was a problem with the way prepareToPlay works
Upvotes: 0