Quote:
Originally Posted by tackey123
I am Trying to play an audio file then wait 2 seconds then go to a method. Right now I am using the sleep command but that stops the whole thread which makes the app crash. So I was wondering if anybody knew how to pause for a little while then go to a method.
here is where the audio and sleep are;
Code:
-(void)loop2 {
NSString *path = [[NSBundle mainBundle] pathForResource:@"LOOP2" ofType:@"aif"];
AVAudioPlayer* theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.delegate = self;
[theAudio play];
sleep(2);
[self random];
}
And here is the method;
Code:
-(void)random {
//do something
}
PLEASE HELP! Thanks!
|
As the other poster said, the AVAudioPlayer class returns immediately when you start it playing.
You want to implement the method audioPlayerDidFinishPlaying:successfully: in your AVAudioPlayer delegate. That method will get called when the sound is finished playing.
In your audioPlayerDidFinishPlaying:successfully: method, you can use the method performSelector:withObject:afterDelay: to tell your control object to play the next sound. The performSelector:withObject:afterDelay: call returns immediately, and starts a timer that causes your method to fire after the specified time-span has elapsed. It saves you the work of creating a timer yourself.
Regards,
Duncan C
WareTo