Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the front camera's deviceUniqueID?

I am trying to write an app that involves both front and rear camera and switching between them. As far as I understand, in the addVideoInput method, I have to change the IDs in

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

But which NSStrings are those IDs?

Or, if it should be done in the other way, please, give a suggestion.

Thank you for help!

like image 647
Knodel Avatar asked May 04 '11 16:05

Knodel


1 Answers

Ok, I have managed to find out a solution. I don't know if it's right or wrong, it was taken from http://www.bunnyhero.org/2010/08/15/turn-your-iphone-into-a-vampire-with-avfoundation-and-ios-4/

Just use

AVCaptureDevice *captureDevice = [self frontFacingCameraIfAvailable];

where frontFacingCameraIfAvailable is:

-(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;
}
like image 135
Knodel Avatar answered Sep 21 '22 07:09

Knodel