AV Foundation in relation to Camera issue

623 views Asked by At

I am trying to be able to use a custom camera, and I am converting code from swift 2 to swift 3; I am pretty much complete; but I am getting this error in relation to devices; I want to have a rear and front facing camera and before in swift 2 you would set the devices like so:

 let devices = AVCaptureDevice.devices(withMediaType: AVMediaTypeVideo) as! [AVCaptureDevice]

now I am using what xcode is telling me to use which is:

let devices = AVCaptureDeviceDiscoverySession(deviceTypes: [AVCaptureDevice], mediaType: AVMediaTypeVideo, position: AVCaptureDevicePosition)

but i am getting this error

cannot convert value of type 'AVCaptureDevice.type' to expected argument type '[AVCaptureDeviceType]'
1

There are 1 answers

0
Ryan H. On

For the deviceTypes parameter you need to pass in an array of one or more AVCaptureDeviceType's. Your choices are:

  • builtInMicrophone
  • builtInWideAngleCamera
  • builtInTelephotoCamera
  • builtInDualCamera

See here for more information on these constants.

With that said, you are probably looking for something like:

let devices = AVCaptureDeviceDiscoverySession(deviceTypes: [AVCaptureDeviceType.builtInWideAngleCamera, AVCaptureDeviceType.builtInTelephotoCamera], mediaType: AVMediaTypeVideo, position: AVCaptureDevicePosition.unspecified)