Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IOS devicesWithMediaType deprecated

I am currently using the method:

NSArray *captureDevices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];

to get a list of devices but XCode is giving me a warning:

Use AVCaptureDeviceDiscoverySession instead

I have looked at the documentation but do not know how to access the devices array

AVCaptureDeviceDiscoverySession *session = [[AVCaptureDeviceDiscoverySession alloc]init];
???
like image 973
Rgfvfk Iff Avatar asked Jun 24 '17 10:06

Rgfvfk Iff


2 Answers

Create AVCaptureDeviceDiscoverySession for your requirement and then call devices method to get Array of currently available devices matching the session’s criteria

Code:

AVCaptureDeviceDiscoverySession *captureDeviceDiscoverySession = [AVCaptureDeviceDiscoverySession discoverySessionWithDeviceTypes:@[AVCaptureDeviceTypeBuiltInWideAngleCamera] 
                                      mediaType:AVMediaTypeVideo 
                                       position:AVCaptureDevicePositionBack];
NSArray *captureDevices = [captureDeviceDiscoverySession devices];

Swift 4+

let discoverySession = AVCaptureDevice.DiscoverySession(deviceTypes: [.builtInWideAngleCamera], mediaType: .video, position: .back)

Available

Device types

Media types

Position

like image 87
Lal Krishna Avatar answered Nov 07 '22 00:11

Lal Krishna


AVCaptureDevice.default(.builtInWideAngleCamera, for: AVMediaTypeVideo, position: .front)

I think something like that would work. I think the AVCapture.DiscoverySession's initializer may be helpful as well. See the documentation and the stack overflow post on something similar in swift. Let me know if it helped!:)

  • https://developer.apple.com/documentation/avfoundation/avcapturedevice
  • How to get front camera, back camera and audio with AVCaptureDeviceDiscoverySession
  • https://developer.apple.com/documentation/avfoundation/avcapturedevice.discoverysession/2361539-init
like image 31
Mihir Thanekar Avatar answered Nov 07 '22 00:11

Mihir Thanekar