Reputation: 47
I am making a metronome app, my sound file is a very brief tick sound, so I need to be able to change the time in between loops to get the right beats per minute. Here's the code to continuously play the tick sound. I would like to specify a delay in between each loop of the audioPlayer.
NSURL *url = [NSURL fileURLWithPath:
[NSString stringWithFormat:@"%@/Metronome-Sound.mp3",
[[NSBundle mainBundle] resourcePath]]];
NSError *error;
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
audioPlayer.numberOfLoops = -1;
[audioPlayer play];
Upvotes: 1
Views: 1259
Reputation: 9876
Since there is no more api's in iPhone. One of the most easiest way is to use [NSThread sleepForTimeInterval:]
in the delegate method -(void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag
EDIT
Simple in .h file after class name implement delegate like this <AVAudioPlayerDelegate>
Then in .m file implement the delegate method as below
-(void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag
{
[NSThread sleepForTimeInterval:5.0];
}
Upvotes: 1