954,529 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Couldn't add video input

I'm trying to make a camera app using AVCaptureSession. For now I just want to see if the video input works or not. But it looks like there is no input and I can't seem to understand why.

- (void)viewDidLoad
{
[super viewDidLoad];

session = [[AVCaptureSession alloc] init];

[self addVideoPreviewLayer];

CGRect layerRect = [[[self view] layer] bounds];

[[self previewLayer] setBounds:layerRect];
[[self previewLayer] setPosition:CGPointMake(CGRectGetMidX(layerRect),
CGRectGetMidY(layerRect))];
[[[self view] layer] addSublayer:[self previewLayer]];


UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
myButton.frame = CGRectMake(80, 320, 200, 44);
[myButton setTitle : @"Click Me!" forState:UIControlStateNormal];
[myButton addTarget:self action: @selector(scanButtonPressed) forControlEvents:UIControlEventTouchDown];
[self.view addSubview:myButton];


}

-(void)addVideoPreviewLayer{

[self setPreviewLayer:[[[AVCaptureVideoPreviewLayer alloc] initWithSession:[self session]] autorelease]];
[[self previewLayer] setVideoGravity:AVLayerVideoGravityResizeAspectFill];

}

-(void) addVideoInput{

AVCaptureDevice *videoDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
if (videoDevice) {
NSError *error;
AVCaptureDeviceInput *videoIn = [AVCaptureDeviceInput deviceInputWithDevice:videoDevice error:&error];
if (!error) {
if ([[self session] canAddInput:videoIn])
[[self session] addInput:videoIn];
else
NSLog(@"Couldn't add video input");
}
else
NSLog(@"Couldn't create video input");
}
else
NSLog(@"Couldn't create video capture device");
}

-(IBAction)scanButtonPressed{

[self addVideoInput];
}

ilaunchpad
Newbie Poster
2 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: