This is an example from the iOS Programming Cookbook, I found it very useful and stressful. After you start recording, you call the stop function with a delay of 10 seconds, when it stops recording, it automatically calls the delegate method audioRecorderDidFinishRecording:successfully.
@implementation ViewController{
AVAudioRecorder *recorder;
AVAudioPlayer *player;
}
- (IBAction)recordPauseTapped:(id)sender {
if (player.playing) {
[player stop];
}
if (!recorder.recording) {
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setActive:YES error:nil];
[recorder record];
[recordPauseButton setBackgroundImage:recordingImage forState:UIControlStateNormal];
[self performSelector:@selector(stopRecording)
withObject:self afterDelay:10.0f];
} else {
[recorder stop];
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setActive:NO error:nil];
}
}
- (void)stopRecording {
[recorder stop];
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setActive:NO error:nil];
}
- (void) audioRecorderDidFinishRecording:(AVAudioRecorder *)avrecorder successfully:(BOOL)flag{
NSLog(@"after 10 sec");
}
source
share