1

I am trying to emulate the functionality in Snapchat that lets the user switch cameras while video recording is in progress.

When I remove the capture session's old input and add a new one my AVCaptureMovieFileOutput instance automatically stops recording.

How does Snapchat accomplish this?

My camera switching code is pretty ordinary but here it is nevertheless:

do{
  self.camera = getCamera(position: (self.front ? AVCaptureDevicePosition.back : AVCaptureDevicePosition.front))
  self.input = try AVCaptureDeviceInput.init(device: self.camera)
}
catch{
  ...
}
captureSession?.beginConfiguration()
captureSession?.removeInput(captureSession?.inputs[0] as! AVCaptureInput!)
captureSession?.addInput(self.input)
captureSession?.commitConfiguration()

The only answers I could find on Stack Overflow were regarding switching the cameras, but none addressed the fact that the recording stopped.

Valli
  • 267
  • 1
  • 2
  • 9

0 Answers0