0
我有以下代碼:devicesWithMediaType已被棄用
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];
但數組設備只有我的背部相機而不是我的前置攝像頭,有幫助嗎?
*,但設備的陣列只有我的後置攝像頭,而不是我的前凸輪* - 這是可以預料的,當你初始化'AVCaptureDeviceDiscoverySession'用'AVCaptureDevicePositionBack' –