您好我正在使用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告诉我我在第二位,但我的屏幕上显示的视频仍在后面......有什么建议吗?
答案 0 :(得分: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];