I'm trying to switch camera while recording video like 'Snapchat' and 'Facebook' behavior. Switch camera work fine before start record video, but need to handle it separately when recording.
Any help appreciate...
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()
}
}