3

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?

Cbas
  • 6,003
  • 11
  • 56
  • 87
  • 1
    I think this http://stackoverflow.com/a/32000238/4601170 might be clear your doubts – Bhavin Bhadani Aug 10 '16 at 05:59
  • that explains a lot, I think I can live with a UI indicator that shows the mic is off and allows a manual re-enable. However - AVCaptureSessionWasInterruptedNotification is called not only when a call starts, but also every time the app enters the background and I don't want to disconnect the audio device in that circumstance.. Is there any way on iOS 8+ to differentiate the interruptions? – Cbas Aug 10 '16 at 20:19
  • (I know I can use AVCaptureSessionInterruptionReasonKey on iOS 9+, but what about iOS 8?) – Cbas Aug 10 '16 at 20:39
  • 1
    for that check this link http://stackoverflow.com/a/32876957/4601170 – Bhavin Bhadani Aug 11 '16 at 04:54
  • you can add your answer if you get it ... might be help to some one :) – Bhavin Bhadani Aug 20 '16 at 05:28
  • Decided to just stop fully supporting iOS 8. who will use it anyway when 10 is out – Cbas Aug 20 '16 at 06:03
  • if I am just switch app from one app 2 another than too `sessionWasInterrupted` was called .. so how do you handle that??? – Bhavin Bhadani Aug 30 '16 at 12:41
  • @EICaptainv2.0 I only disable the audio device if the reason is `AVCaptureSessionInterruptionReasonAudioDeviceInUseByAnotherClient`, `AVCaptureSessionInterruptionReasonVideoDeviceInUseByAnotherClient`, or `AVCaptureSessionInterruptionReasonVideoDeviceNotAvailableWithMultipleForegroundApps`. app switching gives a different reason – Cbas Sep 17 '16 at 01:07

0 Answers0