0

I am trying to add the Front Camera as a subView to my existing View Controller. I would like to set a frame for it, and be able to emulate the way a FaceTime call would look, with the Front Camera showing in the corner. Here is what I have tried so far.

AVCaptureSession *captureSession = [AVCaptureDeviceInput
                                    deviceInputWithDevice:[AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]
                                    error:nil];;
AVCaptureVideoPreviewLayer *previewLayer = [AVCaptureVideoPreviewLayer layerWithSession:captureSession];
UIView *aView = self.view;
previewLayer.frame = aView.bounds; 
[aView.layer addSublayer:previewLayer];

But, this crashes with:

[AVCaptureDeviceInput setVideoPreviewLayer:]: unrecognized selector sent to instance

Any thoughts? I don't need to actually record, just need to see the Front Camera on a smaller screen within the viewcontroller.

user717452
  • 33
  • 14
  • 73
  • 149
  • Why are you creating and assigning an AVCaptureDeviceInput to an AVCaptureSession variable? Are you sure that's your actual code, because that should throw all kinds or warnings and / or errors at compile time. – Brad Larson Apr 23 '12 at 22:24
  • First attempt at using AVCaptureSession, and jumped on first example I could find. All I want is to present a view, and a small subview in the corner. That subview I want to be the Front Camera. Could you point me in the correct direction? – user717452 Apr 23 '12 at 22:31
  • What I'm saying is that the line `AVCaptureSession *captureSession = [AVCaptureDeviceInput …` is wrong. You can't assign an AVCaptureDeviceInput to a AVCaptureSession, because they're unrelated classes. Either you copied the wrong code, or this is seriously broken. It should throw compiler warnings at you, if not outright errors. – Brad Larson Apr 24 '12 at 00:30
  • Definitely no errors or warnings whatsoever...until the app crashes.I got it from https://developer.apple.com/library/mac/#documentation/AVFoundation/Reference/AVCaptureVideoPreviewLayer_Class/Reference/Reference.html in the overview – user717452 Apr 24 '12 at 00:42
  • No you did not. The line `AVCaptureSession *captureSession = <#Get a capture session#>;` means that you need to allocate an AVCaptureSession instance. An AVCaptureDeviceInput is not an AVCaptureSession subclass. They do not allocate and set an AVCaptureDeviceInput to an AVCaptureSession there. I suggest reading the appropriate section within their documentation for how to do this: https://developer.apple.com/library/mac/#documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/04_MediaCapture.html#//apple_ref/doc/uid/TP40010188-CH5-SW2 – Brad Larson Apr 24 '12 at 14:26

0 Answers0