Created
January 23, 2014 23:08
-
-
Save steffex/8588692 to your computer and use it in GitHub Desktop.
Method to request an AVCaptureDevice with a certain position. Method will fallback to the default AVCaptureDevice.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (AVCaptureDevice *) getCaptureDeviceWithPosition:(AVCaptureDevicePosition)position | |
{ | |
AVCaptureDevice *device; | |
// loop through all capture devices with video mediatype | |
for (AVCaptureDevice *d in [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo]) { | |
check if the devices position is the desired one | |
if ([d position] == position) { | |
device = d; | |
} | |
} | |
// if we didnt get the desired device at position, lets go back to the default one | |
if (!device) { | |
device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; | |
} | |
return device; | |
} | |
// USAGE: | |
// get the front facing camera: | |
AVCaptureDevice *device = [self getCaptureDeviceWithPosition:AVCaptureDevicePositionFront]; | |
// get the back facing camera: | |
AVCaptureDevice *device = [self getCaptureDeviceWithPosition:AVCaptureDevicePositionBack]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment