Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 03-02-2011, 12:06 AM   #1 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 40
FDApps is on a distinguished road
Default How do I Stop Animation When Playback Ends using AVAudioPlayer?

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)characterAnimationid)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!
FDApps is offline   Reply With Quote
Old 03-02-2011, 06:19 AM   #2 (permalink)
Registered Member
 
87vert's Avatar
 
Join Date: Sep 2010
Location: Pittsburgh
Posts: 172
87vert is on a distinguished road
Default

According to the Apple Documentation for AVAudioPlayer:
To find out when playback has stopped, use the audioPlayerDidFinishPlaying:successfully: delegate method.

PS. Make sure you use the CODE tags when posting code so it is easier to read.
__________________
Wolfador Coding
Check out my apps:
Crazy Dog Daily Log || Crazy Spouse Daily Log || iCourtReport
87vert is offline   Reply With Quote
Reply

Bookmarks

Tags
animation, avaudioplayer, avrecorder, images, playback

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 367
16 members and 351 guests
Absentia, akphyo, apatsufas, BinHex, dre, Error404, Gaz, gmarro, jeroenkeij, Kirkout, MarkC, mottdog, Music Man, PavelMik, whitey99, Wikiboo
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,666
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, cpsclicker
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 03:19 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0