我正在尝试编写一个涉及前置摄像头和后置摄像头的应用程序,并在它们之间进行切换.据我所知,在addVideoInput方法中,我必须更改其中的ID
AVCaptureDevice *videoDevice = [AVCaptureDevice deviceWithUniqueID:(NSString *)deviceUniqueID];
但NSStrings是哪些ID?
或者,如果要以另一种方式进行,请提出建议.
谢谢你的帮助!
解决方法
好的,我设法找出一个解决方案.我不知道是对还是错,这是从
http://www.bunnyhero.org/2010/08/15/turn-your-iphone-into-a-vampire-with-avfoundation-and-ios-4/开始的
只需使用
AVCaptureDevice *captureDevice = [self frontFacingCameraIfAvailable];
其中frontFacingCameraIf可用的是:
-(AVCaptureDevice *)frontFacingCameraIfAvailable { NSArray *videoDevices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo]; AVCaptureDevice *captureDevice = nil; for (AVCaptureDevice *device in videoDevices) { if (device.position == AVCaptureDevicePositionFront) { 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; }