Switch cameras with avcapturesession

后端 未结 6 1666
借酒劲吻你
借酒劲吻你 2020-11-28 08:06

Using this tutorial here: http://www.musicalgeometry.com/?p=1297 I have created a custom overlay and image capture with AVCaptureSession.

I am attemptin

6条回答
  •  醉梦人生
    2020-11-28 08:33

    Swift 3 version of cameraWithPosition without deprecated warning :

        // Find a camera with the specified AVCaptureDevicePosition, returning nil if one is not found
    func cameraWithPosition(_ position: AVCaptureDevicePosition) -> AVCaptureDevice?
    {
        if let deviceDescoverySession = AVCaptureDeviceDiscoverySession.init(deviceTypes: [AVCaptureDeviceType.builtInWideAngleCamera],
                                                              mediaType: AVMediaTypeVideo,
                                                              position: AVCaptureDevicePosition.unspecified) {
    
            for device in deviceDescoverySession.devices {
                if device.position == position {
                    return device
                }
            }
        }
    
        return nil
    }
    

    If you want, you can also get the new devicesTypes from iPhone 7+ (dual camera) by changing the deviceTypes array.

    Here's a good read : https://forums.developer.apple.com/thread/63347

提交回复
热议问题