ios – 不建议使用devicesWithMediaType

ios – 不建议使用devicesWithMediaType,第1张

概述我有以下代码: NSArray * devices = [ AVCaptureDevice devicesWithMediaType: AVMediaTypeVideo ];// 2. Iterate through the device array and if a device is a camera, check if it's the one we want:for ( AVCapt 我有以下代码:

NSArray * devices = [ AVCaptureDevice devicesWithMediaType: AVMediaTypeVIDeo ];// 2. Iterate through the device array and if a device is a camera,check if it's the one we want:for ( AVCaptureDevice * device in devices ){    if ( useFrontCamera && AVCaptureDevicepositionFront == [ device position ] )    {        // We asked for the front camera and got the front camera,Now keep a pointer to it:        m_camera = device;    }    else if ( !useFrontCamera && AVCaptureDevicepositionBack == [ device position ] )    {        // We asked for the back camera and here it is:        m_camera = device;    }}

警告说不支持devicesWithMediaType,我应该使用AVCaptureDevicediscoverySession,我尝试了以下内容:

AVCaptureDevicediscoverySession *captureDevicediscoverySession = [AVCaptureDevicediscoverySession discoverySessionWithDeviceTypes:@[AVCaptureDeviceTypeBuiltInWIDeAngleCamera]                                       mediaType:AVMediaTypeVIDeo                                        position:AVCaptureDevicepositionBack];NSArray *captureDevices = [captureDevicediscoverySession devices];

但是设备阵列只有我的后置摄像头而不是我的前置摄像头,有什么帮助吗?

解决方法 从 documentation起

Pass AVCaptureDevicepositionUnspecifIEd to search for devices
regardless of position.

因此,使用AVCaptureDevicepositionUnspecifIEd来查找所有捕获设备.

所以代码看起来像这样:

AVCaptureDevicediscoverySession *captureDevicediscoverySession = [AVCaptureDevicediscoverySession discoverySessionWithDeviceTypes:@[AVCaptureDeviceTypeBuiltInWIDeAngleCamera]                                       mediaType:AVMediaTypeVIDeo                                        position: AVCaptureDevicepositionUnspecifIEd]; // here you pass AVCaptureDevicepositionUnspecifIEd to find all capture devicesNSArray *captureDevices = [captureDevicediscoverySession devices];
总结

以上是内存溢出为你收集整理的ios – 不建议使用devicesWithMediaType全部内容,希望文章能够帮你解决ios – 不建议使用devicesWithMediaType所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1209602.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-04
下一篇 2022-06-04

发表评论

登录后才能评论

评论列表(0条)

保存