gpt4 book ai didi

ios - AV Framework 前置摄像头问题

转载 作者:行者123 更新时间:2023-11-29 11:09:31 35 4
gpt4 key购买 nike

您好,我正在使用 AV 框架尝试访问前置摄像头...

这是我这样做的代码..

+ (AVCaptureDevice *)camera
{
NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];

for (AVCaptureDevice *device in devices) {

if ([device position] == AVCaptureDevicePositionFront) {
NSLog(@"Device Position is :%i",device.position);
return device;

}

}

return nil;
}

NSLog 告诉我我在第二个位置,但是我屏幕上显示的视频仍然是从后面...有什么建议吗?

最佳答案

- (AVCaptureDevice *)frontFacingCameraIfAvailable
{
    NSArray *videoDevices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];

    AVCaptureDevice *captureDevice = nil;

for (AVCaptureDevice *device in videoDevices) 
{
  if (device.position == AVCaptureDevicePositionFron 
  {
        captureDevice = device;
        break;
    }
}
//  couldn't find one on the front, so just get the default video device.
if (!captureDevice)
    {
    captureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
}
return captureDevice;
}


AVCaptureDevice *captureDevice = nil;

if(frontCamera == true){
captureDevice = [self frontFacingCameraIfAvailable];
}

captureInput = [AVCaptureDeviceInput
deviceInputWithDevice:captureDevice
error:nil];

关于ios - AV Framework 前置摄像头问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12148266/

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