AV基金会与相机问题有关

时间:2017-01-06 22:03:00

标签: swift swift3 avcapturedevice

我正在尝试使用自定义相机,我正在将代码从swift 2转换为swift 3;我非常完整;但我收到与设备有关的错误;我想要一个后置和前置摄像头,在swift 2之前,你可以像这样设置设备:

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

现在我正在使用xcode告诉我使用的是:

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

但我收到此错误

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

1 个答案:

答案 0 :(得分:1)

对于deviceTypes参数,您需要传入一个或多个AVCaptureDeviceType的数组。您的选择是:

  • builtInMicrophone
  • builtInWideAngleCamera
  • builtInTelephotoCamera
  • builtInDualCamera

有关这些常量的更多信息,请参阅here

话虽如此,你可能正在寻找类似的东西:

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