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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.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 05-15-2009, 02:31 PM   #1 (permalink)
Registered Member
 
DenVog's Avatar
 
Join Date: Jan 2009
Location: Silicon Valley, USA
Posts: 622
Question Repeat Animation Until Sound Finishes Playing

Can someone help me understand how I can get an animation to repeat until a sound file has finished playing? Right now I have a button that plays a sound and fires this animation code. The animation is set to repeat 3 times, but my sound files are differing lengths. So my animation is not always in synch with my sound.
Code:
- (void) itemAnimate {

	// starts the animation
	[UIView beginAnimations:nil context:NULL];
	// sets the length of the animation
	[UIView setAnimationDuration:.25];
	// tells animation to play backward, needs RepeatCount to work
	[UIView setAnimationRepeatAutoreverses:YES];
	// sets number of times animation repeats, default value is 0, which specifies to repeat the animation indefinitely; and 1e100f means go until removed from view
	[UIView setAnimationRepeatCount:3];
	// moves the animated area
       itemView.transform = CGAffineTransformTranslate(mouthView.transform, 0.0, 20.0);
	// resets the position of view
	itemView.transform = CGAffineTransformIdentity;
	// ends animation
	[UIView commitAnimations];

}
I see that there is a callback that can be used when a sound is done playing, but how would I use it to stop an animation in progress?
Code:
AudioServicesAddSystemSoundCompletion(soundOne, NULL, NULL, simpleSoundDone, NULL);
Thanks for any guidance
DenVog is offline   Reply With Quote
Old 02-23-2010, 06:41 PM   #2 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 77
Default did you find a solution

Did you ever find a solution to this question, I am searching for the same thing?
Thank you!

Quote:
Originally Posted by DenVog View Post
Can someone help me understand how I can get an animation to repeat until a sound file has finished playing? Right now I have a button that plays a sound and fires this animation code. The animation is set to repeat 3 times, but my sound files are differing lengths. So my animation is not always in synch with my sound.
Code:
- (void) itemAnimate {

	// starts the animation
	[UIView beginAnimations:nil context:NULL];
	// sets the length of the animation
	[UIView setAnimationDuration:.25];
	// tells animation to play backward, needs RepeatCount to work
	[UIView setAnimationRepeatAutoreverses:YES];
	// sets number of times animation repeats, default value is 0, which specifies to repeat the animation indefinitely; and 1e100f means go until removed from view
	[UIView setAnimationRepeatCount:3];
	// moves the animated area
       itemView.transform = CGAffineTransformTranslate(mouthView.transform, 0.0, 20.0);
	// resets the position of view
	itemView.transform = CGAffineTransformIdentity;
	// ends animation
	[UIView commitAnimations];

}
I see that there is a callback that can be used when a sound is done playing, but how would I use it to stop an animation in progress?
Code:
AudioServicesAddSystemSoundCompletion(soundOne, NULL, NULL, simpleSoundDone, NULL);
Thanks for any guidance
carlandrews is offline   Reply With Quote
Old 02-23-2010, 07:29 PM   #3 (permalink)
Registered Member
 
DenVog's Avatar
 
Join Date: Jan 2009
Location: Silicon Valley, USA
Posts: 622
Default

Quote:
Originally Posted by carlandrews View Post
Did you ever find a solution to this question, I am searching for the same thing?
Thank you!
It has been a long time. I don't think you can stop the animation directly, but can stop a timer. So as I recall I run the animation with a timer on repeat. I then use the callback from when the sound completes to invalidate the timer (thus stopping the animation). Does that help?
DenVog is offline   Reply With Quote
Old 02-23-2010, 07:56 PM   #4 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 77
Default still question

Not sure. Don't know about the callback when sound completes, have not read about that and if there is a callback when the sound completes why do you need a timer? Couldn't you just execute the next function and call next screen once you are alerted the sound has finished? How do I get it to tell me when a sound file is done playing, that seems very useful?

Thanks!

Quote:
Originally Posted by DenVog View Post
It has been a long time. I don't think you can stop the animation directly, but can stop a timer. So as I recall I run the animation with a timer on repeat. I then use the callback from when the sound completes to invalidate the timer (thus stopping the animation). Does that help?
carlandrews is offline   Reply With Quote
Old 02-23-2010, 08:01 PM   #5 (permalink)
Registered Member
 
DenVog's Avatar
 
Join Date: Jan 2009
Location: Silicon Valley, USA
Posts: 622
Default

Quote:
Originally Posted by carlandrews View Post
Not sure. Don't know about the callback when sound completes, have not read about that and if there is a callback when the sound completes why do you need a timer? Couldn't you just execute the next function and call next screen once you are alerted the sound has finished? How do I get it to tell me when a sound file is done playing, that seems very useful?

Thanks!
Search for forum for "completionCallback".

The thread I started was about stopping an animation, not switching screens. As I stated, I don't think you can stop an animation directly. Stopping a timer that was running an animation worked for me..
DenVog is offline   Reply With Quote
Old 02-23-2010, 08:02 PM   #6 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 77
Default Thanks!

Thanks, I will look it up.

Quote:
Originally Posted by DenVog View Post
Search for forum for "completionCallback".

The thread I started was about stopping an animation, not switching screens. As I stated, I don't think you can stop an animation directly.
carlandrews is offline   Reply With Quote
Reply

Bookmarks

Tags
animation, sound, synch

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: 267
20 members and 247 guests
ADY, AragornSG, Bertrand21, Dani77, Dattee, Duncan C, fkmtc, HDshot, HemiMG, iDifferent, JasonR, macquitzon216, mer10, prchn4christ, Promo Dispenser, Rudy, sacha1996, sneaky, spiderguy84, theone8one
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,231
Posts: 380,768
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

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