Callback when phone call ends? (to resume AVCaptur

2019-07-09 23:54发布

I have a video camera app and I would like it to allow users to capture content while on the phone.

I can do this by disconnecting the audio capture when the phone call is received and the session is interrupted, but because the session is no longer interrupted, I now have no way of knowing when the phone call ends and it is ok to reconnect the audio device.

If I use this callbacks for AVCaptureSessionWasInterruptedNotification and AVCaptureSessionInterruptionEndedNotification:

- (void)sessionWasInterrupted:(NSNotification *)notification {
    NSLog(@"session was interrupted");

    // disconnect the audio device when a call is started

    AVCaptureDevice *device = [[self audioInput] device];
    if ([device hasMediaType:AVMediaTypeAudio]) {
      [[self session] removeInput:[self audioInput]];
      [self setAudioInput:nil];
    }
}

- (void)sessionInterruptionEnded:(NSNotification *)notification {
    NSLog(@"session interuption ended");

    // reconnect the audio device when the call ends
    // PROBLEM: disconnecting the audio device triggers this callback before the phone call ends...

    AVCaptureDevice *device = [[self audioInput] device];
    if ([device hasMediaType:AVMediaTypeAudio]) {
        if ([[self session] canAddInput:[self audioInput]])
            [[self session] addInput:[self audioInput]];
    }
}

I get an infinite loop of both of them being called one after another for the entire duration of the phone call and the camera is frozen. If I don't reconnect the device in the second function, the camera keeps working, but sessionInterruptionEnded is not called again when the phone call ends.

Is there a callback for when the phone call ends?

0条回答
登录 后发表回答