0

I downloaded the AVCam example from Apple and I tried to migrate the xib files to Storyboard.

The problem is the "newCaptureVideoPreviewLayer" is not displaying the video in the view... The view is referencing outlet to "videoPreviewView" this is the view where the video should appear.

This is the code from AVCam example, I just pasted the code and remove what was unnecessary:

- (void)viewDidLoad
{
    if ([self captureManager] == nil) {
    AVCamCaptureManager *manager = [[AVCamCaptureManager alloc] init];
    [self setCaptureManager:manager];
    [manager release];

    [[self captureManager] setDelegate:self];

    if ([[self captureManager] setupSession]) {
        // Create video preview layer and add it to the UI
        AVCaptureVideoPreviewLayer *newCaptureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:[[self captureManager] session]];
        UIView *view = [self videoPreviewView];
        CALayer *viewLayer = [view layer];
        [viewLayer setMasksToBounds:YES];

        CGRect bounds = [view bounds];
        [newCaptureVideoPreviewLayer setFrame:bounds];

        [newCaptureVideoPreviewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];

        [viewLayer insertSublayer:newCaptureVideoPreviewLayer below:[[viewLayer sublayers] objectAtIndex:0]];

        [self setCaptureVideoPreviewLayer:newCaptureVideoPreviewLayer];
        [newCaptureVideoPreviewLayer release];

        // Start the session. This is done asychronously since -startRunning doesn't return until the session is running.
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            [[[self captureManager] session] startRunning];
        });
    }
}

[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}

Someone have a sugestion?

1 Answers1

0

You may want to make sure your camerapreview view is the top subview in your storyboard. Add it last or use BringSubviewToFront api.

I guess the camera is saving a picture to your photos camera roll if you press take photo? if not, its probably an issue with the init code. I had to change the ismirrored deprecated code for ios 6.

DEzra
  • 2,978
  • 5
  • 31
  • 50