1

您好我正在使用 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 告诉我我在第二个位置,但是我屏幕上显示的视频仍然来自后面……有什么建议吗?

4

1 回答 1

2
- (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];   
于 2012-08-27T19:32:29.007 回答