Crashes when using AVAudioPlayer on iPhone
- by mindthief
Hi all,
I am trying to use AVAudioPlayer to play some sounds in quick succession. When I invoke the sound-playing function less frequently so that the sounds play fully before the function is invoked again, the application runs fine. But if I invoke the function quickly in rapid succession (so that sounds are played while the previous sounds are still being played), the app eventually crashes after ~20 calls to the function, with the message "EXC_BAD_ACCESS". Here is code from the function:
NSString *nsWavPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:wavFileName];
AVAudioPlayer* theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:nsWavPath] error:NULL];
theAudio.delegate = self;
[theAudio play];
As mentioned in another thread, I implemented the following delegate function:
- (void) audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag
{
if(!flag)
NSLog(@"audio did NOT finish successfully\n");
[player release];
}
But the app still crashes after around ~20 rapid calls to the function. Any idea what I'm doing wrong?