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

后端 未结 11 1393
闹比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:06

    For my video capture app I'm using the following code to get the mic, front and rear camera and I've tested this code from iOS 7 to 10.0.2.

            var frontCamera : AVCaptureDevice?
            var rearCamera : AVCaptureDevice?
    
            captureSession = AVCaptureSession()
    
            let devices = AVCaptureDevice.devicesWithMediaType(AVMediaTypeVideo)
    
            let audioDevices = AVCaptureDevice.devicesWithMediaType(AVMediaTypeAudio)
    
            for mic in audioDevices {
                audioDevice = mic as? AVCaptureDevice
                audioCapturePossible = true
            }
    
            for device in devices {
                if device.position == AVCaptureDevicePosition.Front {
                    frontCamera = device as? AVCaptureDevice
                    hasFrontCamera = true
                }
                else if device.position == AVCaptureDevicePosition.Back {
                    rearCamera = device as? AVCaptureDevice
                    hasRearCamera = true
                }
    
            }
    

提交回复
热议问题