Callback when phone call ends? (to resume AVCaptureSession)

谁说胖子不能爱 提交于 2019-12-22 10:33:52

问题


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?

来源:https://stackoverflow.com/questions/38862181/callback-when-phone-call-ends-to-resume-avcapturesession

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!