AVCam example iPad landscape
I am working with Apple's AVCam code example. I have altered the interface
to work only with the iPad, things seem to be working okay. I have the
video preview on screen but it seems scaled and out of place, almost as if
it is a portrait orientation?
Here is a picture of what is going on:
Obviously I would like the preview to be in landscape (ie take up the full
width of the screen). Although it is not clear from the context of the
image, but it is zoomed in very far by default, I am assuming is is a
product of AVLayerVideoGravityResizeAspectFill and this view somehow being
in portrait?
I have the app setup to only allow Landscape Left and Right, and I would
like the video preview to flip when the device orientation is changed, I
can't seem to get it to do that, even in its current state.
Here are what I assume to be the important parts (if more is needed for
you all to see, please tell me!)
From AVCamViewController.m:
AVCaptureVideoPreviewLayer *newCaptureVideoPreviewLayer =
[[AVCaptureVideoPreviewLayer alloc] initWithSession:[[self
captureManager] session]];
UIView *view = [self videoPreviewView];
CALayer *viewLayer = [view layer];
[viewLayer setMasksToBounds:YES];
//orientation
newCaptureVideoPreviewLayer.orientation =
UIInterfaceOrientationLandscapeLeft;
CGRect bounds = [view bounds];
[newCaptureVideoPreviewLayer setFrame:bounds];
/*if ([newCaptureVideoPreviewLayer isOrientationSupported]) {
NSLog(@"Hello");
[newCaptureVideoPreviewLayer
setOrientation:AVCaptureVideoOrientationLandscapeLeft|AVCaptureVideoOrientationLandscapeRight];
}*/
if ([newCaptureVideoPreviewLayer
respondsToSelector:@selector(connection)])
{
if ([newCaptureVideoPreviewLayer.connection
isVideoOrientationSupported])
{
NSLog(@"hello1");
//self.interfaceOrientation
[newCaptureVideoPreviewLayer.connection
setVideoOrientation:self.interfaceOrientation];
}
}
else
{
// Deprecated in 6.0; here for backward compatibility
if ([newCaptureVideoPreviewLayer isOrientationSupported])
{
NSLog(@"hello2");
[newCaptureVideoPreviewLayer
setOrientation:self.interfaceOrientation];
}
}
Now AVCaptureManager.m:
- (void)deviceOrientationDidChange
{
UIDeviceOrientation deviceOrientation = [[UIDevice currentDevice]
orientation];
/*if (deviceOrientation == UIDeviceOrientationPortrait)
orientation = AVCaptureVideoOrientationPortrait;
else if (deviceOrientation == UIDeviceOrientationPortraitUpsideDown)
orientation = AVCaptureVideoOrientationPortraitUpsideDown;
// AVCapture and UIDevice have opposite meanings for landscape left
and right (AVCapture orientation is the same as
UIInterfaceOrientation)
else*/ if (deviceOrientation == UIDeviceOrientationLandscapeLeft){
orientation = AVCaptureVideoOrientationLandscapeRight;
NSLog(@"right");
}
else if (deviceOrientation == UIDeviceOrientationLandscapeRight){
orientation = AVCaptureVideoOrientationLandscapeLeft;
NSLog(@"left");
}
// Ignore device orientations for which there is no corresponding
still image orientation (e.g. UIDeviceOrientationFaceUp)
}
From the init method:
NSNotificationCenter *notificationCenter = [NSNotificationCenter
defaultCenter];
[self setDeviceConnectedObserver:[notificationCenter
addObserverForName:AVCaptureDeviceWasConnectedNotification
object:nil queue:nil usingBlock:deviceConnectedBlock]];
[self setDeviceDisconnectedObserver:[notificationCenter
addObserverForName:AVCaptureDeviceWasDisconnectedNotification
object:nil queue:nil usingBlock:deviceDisconnectedBlock]];
[[UIDevice currentDevice]
beginGeneratingDeviceOrientationNotifications];
[notificationCenter addObserver:self
selector:@selector(deviceOrientationDidChange)
name:UIDeviceOrientationDidChangeNotification object:nil];
orientation = AVCaptureVideoOrientationLandscapeLeft;
Any help is greatly appreciated!
No comments:
Post a Comment