Skip to content

Instantly share code, notes, and snippets.

@Rich86man
Created October 17, 2012 17:21
Show Gist options
  • Save Rich86man/3906840 to your computer and use it in GitHub Desktop.
Save Rich86man/3906840 to your computer and use it in GitHub Desktop.
- (AVCaptureSession*)captureSession
{
if(!_captureSession) {
_captureSession = [[AVCaptureSession alloc] init];
_captureSession.sessionPreset = AVCaptureSessionPresetMedium;
AVCaptureDeviceInput* videoInput = [AVCaptureDeviceInput deviceInputWithDevice:[AVCaptureDevice frontFacingCameraIfAvailable] error:nil];
AVCaptureDeviceInput * audioInput = [AVCaptureDeviceInput deviceInputWithDevice:[AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio] error:nil];
[self.captureSession beginConfiguration];
[_captureSession addInput:videoInput];
[_captureSession addInput:audioInput];
[self.captureSession addOutput:self.fileOutput];
[self.videoConnection setVideoOrientation:[[UIDevice currentDevice] orientation]];
[self.captureSession commitConfiguration];
}
return _captureSession;
}
- (AVCaptureVideoPreviewLayer*)captureVideoPreviewLayer
{
if (!_captureVideoPreviewLayer) {
_captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:self.captureSession];
_captureVideoPreviewLayer.frame = self.videoPlaceholderView.bounds;
_captureVideoPreviewLayer.orientation = [[UIDevice currentDevice] orientation];
_captureVideoPreviewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
}
return _captureVideoPreviewLayer;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment