Skip to content

Instantly share code, notes, and snippets.

@yojimbocorp
Created June 19, 2014 23:01
Show Gist options
  • Save yojimbocorp/f2e1300835dd7a65394a to your computer and use it in GitHub Desktop.
Save yojimbocorp/f2e1300835dd7a65394a to your computer and use it in GitHub Desktop.
Tu Telemundo Code Snippet
- (IBAction)toggleCameras:(id)sender {
if (self.toggleCameraButton.enabled == NO) {
DLog(@"Don't allow toggle while button not enabled");
return;
}
if (self.isRecording) {
DLog(@"Don't allow toggle while recording");
return;
}
NSError *error;
AVCaptureDevicePosition position = [[self.activeVideoInput device] position];
AVCaptureDeviceInput *videoInput;
if (position == AVCaptureDevicePositionBack) {
videoInput = [[AVCaptureDeviceInput alloc] initWithDevice:[self cameraWithPosition:AVCaptureDevicePositionFront] error:&error];
self.previewLayer.transform = CATransform3DMakeRotation(M_PI, 0.0f, 1.0f, 0.0f);
} else {
videoInput = [[AVCaptureDeviceInput alloc] initWithDevice:[self cameraWithPosition:AVCaptureDevicePositionBack] error:&error];
self.previewLayer.transform = CATransform3DIdentity;
}
if (videoInput) {
[self.captureSession beginConfiguration];
[self.captureSession removeInput:self.activeVideoInput];
if ([self.captureSession canAddInput:videoInput]) {
[self.captureSession addInput:videoInput];
self.activeVideoInput = videoInput;
}
[self.captureSession commitConfiguration];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment