How to get front camera, back camera and audio with AVCaptureDeviceDiscoverySession

后端 未结 11 1403
闹比i
闹比i 2020-12-12 20:58

Before iOS 10 came out I was using the following code to get the video and audio capture for my video recorder:

 for device in AVCaptureDevice.devices()
 {
          


        
11条回答
  •  我在风中等你
    2020-12-12 21:13

    Swift 3

    For selecting the back camera:(also you can change .back as needed)

    For selecting another deviceType simple add it inside the [ ] (i.e:

    [deviceTypeCamera, AVCaptureDeviceType.builtInMicrophone]

    (or create a private let... like I did in the code with the back camera)

     private let position = AVCaptureDevicePosition.back
     private let deviceTypeBackCamera = AVCaptureDeviceType.builtInWideAngleCamera
    
     private func selectCaptureDevice() -> AVCaptureDevice? {
        return AVCaptureDeviceDiscoverySession(deviceTypes: [deviceTypeBackCamera], mediaType: AVMediaTypeVideo, position: position).devices.first
    
     }
    

提交回复
热议问题