gpt4 book ai didi

ios - devicesWithMediaType 已弃用

转载 作者:可可西里 更新时间:2023-11-01 17:03:30 32 4
gpt4 key购买 nike

我有以下代码:

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 devices

NSArray *captureDevices = [captureDeviceDiscoverySession devices];

关于ios - devicesWithMediaType 已弃用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45934260/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com