I am running an image animation during playback of a recorded file using AVAudioRecorder/AVAudioPlayer and want to stop the animation at the time the audio file stops. Right now I can only stop the animation when a button is pressed. Does anyone know how to be notified of playback ending?
Here are portions of my code:
//From the animationcontroller:
-(IBAction)characterAnimation

id)sender
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
if ([audioSession setActive:YES error:nil]) {
NSArray *images = [NSArray arrayWithObjects:
[UIImage imageNamed:@"action-amin0.png"],
[UIImage imageNamed:@"action-amin1.png"],
[UIImage imageNamed:@"action-amin0.png"],
[UIImage imageNamed:@"action-amin1.png"],
[UIImage imageNamed:@"action-amin0.png"],
[UIImage imageNamed:@"action-amin4.png"],
[UIImage imageNamed:@"action-amin1.png"],
nil];
CGRect frame = CGRectMake(0,0,768,1024);
imageView = [[UIImageView alloc] initWithFrame:frame];
imageView.animationImages = images;
imageView.contentMode = UIViewContentModeScaleAspectFit;
imageView.animationDuration = 2;
imageView.animationRepeatCount = 0;
[containerView addSubview:imageView];
[imageView startAnimating];
NSLog(@"Character is animating");
}else {
[self stopAnimation];
}}
-(IBAction) stopAnimation {
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
if ([audioSession setActive:YES error:nil]) {
[imageView stopAnimating];
NSLog(@"Character stopped animating");
}
}
//From the audiocontroller:
-(void) playIt
{
AVAudioSession *session = [AVAudioSession sharedInstance];
if (![session setActive:YES error:nil])
{
[self stopSound];
[(Application*)[[UIApplication sharedApplication] delegate] stopAnimation];
[self seekToTime:kCMTimeZero];
}else{
NSError *error = nil;
player= [[AVAudioPlayer alloc] initWithContentsOfURL:recordedTmpFile error:&error];
[player prepareToPlay];
[player play];
NSLog(@"Player is playing");
}
}
Thanks for the help!