iOS 文档说您可以在会话运行时添加和删除输入,例如在前后摄像头之间切换。
但是,当我尝试这个时,我的会话停止了。我锁定会话beginConfiguration
并commitConfiguration
调用如下:
- (void)switchCamera:(UIButton *)sender {
dispatch_async([self sessionQueue], ^{
AVCaptureSession *session = self.captureSession;
[session beginConfiguration];
AVCaptureInput *currentInput = self.currentCameraIsBack ? self.videoDeviceInputBack : self.videoDeviceInputFront;
AVCaptureInput *newInput = self.currentCameraIsBack ? self.videoDeviceInputFront : self.videoDeviceInputBack;
[session removeInput:currentInput];
[session addInput:newInput];
self.currentCameraIsBack = !self.currentCameraIsBack;
[session setSessionPreset:AVCaptureSessionPresetMedium];
[self setCameraOutputProperties];
[session commitConfiguration];
});
}
我正在输出到AVCaptureMovieFileOutput
. 我需要做些什么来配置此会话以使其可切换吗?
(请注意,此问题中的 OP正在尝试添加新输入而不删除旧输入,这不是这里的问题)