更新时间:2023-10-22 20:10:34
您需要使用 AVCaptureSessionWasInterruptedNotification
和 AVCaptureSessionInterruptionEndedNotification
回调并在会话中断时断开音频捕获:
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
现在关于如何在通话结束后重新连接音频..让我知道你是否弄明白,从iOS 10开始看似乎不可能:回电时电话结束了吗? (恢复AVCaptureSession)
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)