Reputation: 25
in my project I have multiple recordings taken from the iPhones microphone which I loop with this code
-(IBAction)loop1{
NSError *error;
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:temporaryRecFile error:&error];
audioPlayer.numberOfLoops = 100;
[audioPlayer play];
}
and stop with this code
-(IBAction)loopstop1{
audioPlayer.numberOfLoops = 0;
[audioPlayer stop];
}
When more than one recording is looping however this stop method only stops the last recording that was set to loop, I'm wondering if there is anyway to break out of all audio loops, or break these specific loops, as I am only managing to stop the last recording I have looped.
thanks for any help or advice
Upvotes: 1
Views: 106
Reputation: 22820
What I would do :
NSMutableArray
to hold the audioPlayer
sAdd your AVAudioPlayer
objects to your array
AVAudioPlayer* newLoop = [[AVAudioPlayer alloc] initWithContentsOfURL:temporaryRecFile
error:&error];
newLoop.numberOfLoops = 100;
[loopsArray addObject:newLoop];
Pass an index to each of the start / stop functions, to know which audioPlayer
to start/stop.
Hint : To stop all of them, just call the stop
method on each of your loops store in the loopsArray
Upvotes: 1