Camera Freeze when open app while call is running

谁都会走 提交于 2019-12-03 03:25:29

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)

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