Question

We are recording audio with AVAudioRecorder but when ever we receive any incoming call Recording gets stopped. If we try to Resume recording again then it will start from the beginning. I have checked the Voice Memos(iOS Apple Application) & find the same problem. I have also checked the Audio Queue services Sample Code (SpeakHere) But same problem is there. So Please help how to resume audio recording after incoming call?

Note:- I Know there are many question related to audio recording But unable to find solution.So please Help, Your help is greatly appreciated. Thanks in advance.

Was it helpful?

Solution

It is possible in iOS,to resume a audio recording after incoming call.Basic concept behind this is the use of AVAudioSession and AudioQueue ,when you receive a incoming call on your device it would give a kAudioSessionBeginInterruption and on disconnecting the call you got a kAudioSessionEndInterruption......on receiving a incoming call ,just pause the audio queue and then [[AVAudioSession sharedInstance]setActive:NO error:nil]; ......Then on the kAudioSessionEndInterruption ,when the call ends,just resume the paused queue and [[AVAudioSession sharedInstance]setActive:YES error:nil];

This will work......I have successfully run the program and able to continue the recording after receiving an incoming call......

Hope this will help you.......

OTHER TIPS

Apple explain AVAudioSessionInterruption observer as a new method to handle interruptions. Apple explains it in Swift at this page but for someones that search for objective-c code this github issue must be useful.

You need to handle audio interrupts like

AVAudioSession *session = [AVAudioSession sharedInstance];
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(audioSessionInterruptionNotification:)
                                             name:AVAudioSessionInterruptionNotification
                                           object:session];

where your audio session interruption notification AVAudioSessionInterruptionNotification is something like

-(void)audioSessionInterruptionNotification:(NSNotification*)notification {

NSString* seccReason = @"";

//Check the type of notification, especially if you are sending multiple AVAudioSession events here
NSLog(@"Interruption notification name %@", notification.name);

if ([notification.name isEqualToString:AVAudioSessionInterruptionNotification]) {
    seccReason = @"Interruption notification received";

    //Check to see if it was a Begin interruption
    if ([[notification.userInfo valueForKey:AVAudioSessionInterruptionTypeKey] isEqualToNumber:[NSNumber numberWithInt:AVAudioSessionInterruptionTypeBegan]]) {
        seccReason = @"Interruption began";

    } else if([[notification.userInfo valueForKey:AVAudioSessionInterruptionTypeKey] isEqualToNumber:[NSNumber numberWithInt:AVAudioSessionInterruptionTypeEnded]]){
        seccReason = @"Interruption ended!";
        //Resume your audio
    }
}
}

You need to write your handling code then for interruption begin and end.

Use the AVFoundation Delegate Methods,

-(void)audioRecorderBeginInterruption:(AVAudioRecorder *)recorder
{
    [audiorecorder pause];
}
-(void)audioRecorderEndInterruption:(AVAudioRecorder *)recorder
{
    [audiorecorder record];
} 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top