Skip to content

Instantly share code, notes, and snippets.

@kishaningithub
Created June 4, 2015 17:51
Show Gist options
  • Save kishaningithub/0609fe899985be383a48 to your computer and use it in GitHub Desktop.
Save kishaningithub/0609fe899985be383a48 to your computer and use it in GitHub Desktop.
IOS Feed Live Capture
class ViewController: UIViewController {
var session:AVCaptureSession!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func viewWillAppear(animated: Bool) {
session = AVCaptureSession()
session.sessionPreset = AVCaptureSessionPresetPhoto
var inputDevice = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeVideo)
var deviceInput = AVCaptureDeviceInput.deviceInputWithDevice(inputDevice, error: nil) as! AVCaptureDeviceInput
session.addInput(deviceInput)
var previewLayer:AVCaptureVideoPreviewLayer = AVCaptureVideoPreviewLayer(session: session)
previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill
previewLayer.frame = self.view.frame
self.view.layer.insertSublayer(previewLayer, atIndex: 0)
session.startRunning()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment