我有一个录音会话,但是当我更换相机时,这只保存第一个摄像头的第一个视频,然后开关不保存,我该怎么做?
我使用此功能切换和加载新相机:
- (IBAction)switchCameras:(id)sender
AVCaptureDevicePosition desiredPosition;
if (isUsingFrontFacingCamera)
desiredPosition = AVCaptureDevicePositionBack;
else
desiredPosition = AVCaptureDevicePositionFront;
for (AVCaptureDevice *d in [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo]) {
if ([d position] == desiredPosition) {
[[previewLayer session] beginConfiguration];
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:d error:nil];
for (AVCaptureInput *oldInput in [[previewLayer session] inputs]) {
[[previewLayer session] removeInput:oldInput];
}
[[previewLayer session] addInput:input];
[[previewLayer session] commitConfiguration];
break;
}
}
isUsingFrontFacingCamera = !isUsingFrontFacingCamera;
}
谢谢!
答案 0 :(得分:1)
删除旧的AVCaptureDeviceInput
并添加新的AVCaptureDeviceInput
后,您可能需要重新创建AVCaptureConnection
,调整从新捕获输入到捕获输出的流量。