Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

THEDEAN911

macrumors newbie
Original poster
I'm trying to get the camera video preview working for my app. Right now I get a black screen on the phone and a "Thread 1 breakpoint 1.2" on

Code:
@property (weak, nonatomic) IBOutlet UIView *videoPreviewLayer;

videoPreviewLayer is the view that the preview should show up on.

This is my viewController.h

Code:
#import <UIKit/UIKit.h>
@class AVCaptureVideoPreviewLayer;
@interface ViewController : UIViewController
- (IBAction)imageCapture:(id)sender;
@property (weak, nonatomic) IBOutlet UIView *videoPreviewLayer;

@end

This is my viewController.m

Code:
#import "ViewController.h"
#import <AVFoundation/AVFoundation.h>


@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    AVCaptureSession *session = [[AVCaptureSession alloc] init];
    session.sessionPreset = AVCaptureSessionPresetPhoto;
    AVCaptureDevice *device = [AVCaptureDevice
                               defaultDeviceWithMediaType:AVMediaTypeVideo];
    AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:NULL];
    [session addInput:input];
//    dispatch_queue_t queue = dispatch_queue_create("MyQueue", NULL);
//    [output setSampleBufferDelegate:self queue:queue];
    AVCaptureVideoPreviewLayer *preview = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];
    CALayer *viewLayer = [_videoPreviewLayer layer];
    [viewLayer setMasksToBounds:YES];
    CGRect bounds = [_videoPreviewLayer bounds];
    [preview setFrame:bounds];
//    preview.frame = self.view.frame;
//    [self.view.layer addSublayer:preview];
    [session startRunning];
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)imageCapture:(id)sender {
}

- (void)captureOutput:(AVCaptureOutput *) captureOutput
    didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection
{
   // CFShow(sampleBuffer);
}
@end

Any ideas as to what's going on?

Thanks in advance 🙂
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.