我正在尝试切换相机,同时录制像'Snapchat'和'Facebook'这样的视频。在开始录制视频之前切换摄像头工作正常,但录制时需要单独处理。
任何帮助表示赞赏......
public func switchCamera() {
guard isVideoRecording != true else {
//TODO: Handle switch camera when recording in here
return
}
guard session.isRunning == true else {
return
}
switch currentCamera {
case .front:
currentCamera = .rear
case .rear:
currentCamera = .front
}
session.stopRunning()
sessionQueue.async { [unowned self] in
// remove and re-add inputs and outputs
for input in self.session.inputs {
self.session.removeInput(input as! AVCaptureInput)
}
// add new input
self.addInputs()
self.session.startRunning()
}
}