Camera Freeze when open app while call is running

前端 未结 1 1625
迷失自我
迷失自我 2020-12-15 11:51

I have created a camera using AVCaptureSession. I have configured that for both Photo and Video recording modes.

Camera and App i

相关标签:
1条回答
  • 2020-12-15 12:23

    You need to use the AVCaptureSessionWasInterruptedNotification and AVCaptureSessionInterruptionEndedNotification callbacks and disconnect the audio capture while the session is interrupted:

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sessionWasInterrupted:) name:AVCaptureSessionWasInterruptedNotification object:self.session];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sessionInterruptionEnded:) name:AVCaptureSessionInterruptionEndedNotification object:self.session];
    // note that self.session is an AVCaptureSession
    

    -

    - (void)sessionWasInterrupted:(NSNotification *)notification {
      NSLog(@"session was interrupted");
    
      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");
    }
    // note that [self audioInput] is a getter for an AVCaptureDeviceInput
    

    This will allow the camera to continue running and allows it to capture stills / silent video

    Now as for how to reconnect the audio after the call ends.. let me know if you figure it out, seemed impossible as of iOS 10: Callback when phone call ends? (to resume AVCaptureSession)

    0 讨论(0)
提交回复
热议问题