2011-05-04 86 views
13

我正在嘗試編寫一個涉及前後攝像頭並在它們之間切換的應用程序。據我瞭解,在addVideoInput方法,我必須要改變的ID在什麼是前置攝像頭的deviceUniqueID?

AVCaptureDevice *videoDevice = [AVCaptureDevice deviceWithUniqueID:(NSString *)deviceUniqueID]; 

但其NSString的是那些ID?

或者,如果應該以其他方式完成,請提出建議。

謝謝你的幫忙!

回答

28

好吧,我已經設法找出解決方案。我不知道這是否是正確的還是錯誤的,它是從http://www.bunnyhero.org/2010/08/15/turn-your-iphone-into-a-vampire-with-avfoundation-and-ios-4/

採取只要使用

AVCaptureDevice *captureDevice = [self frontFacingCameraIfAvailable]; 

其中frontFacingCameraIfAvailable是:

-(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; 
} 
0

可以通常得到使用

前方照相機
AVCaptureDevice *frontalCamera = [AVCaptureDevice deviceWithUniqueID:@"com.apple.avfoundation.avcapturedevice.built-in_video:1"]; 

但是我寧願使用你接受的方法 - 這一個是不安全的。

相關問題