2011-10-23 1 views
4

Cela fait ma tête dansComment enregistrer une vidéo à l'écran dans une application de paysage?

Je travaille à partir de cet exemple de projet:. https://github.com/jj0b/AROverlayExample

Cela fonctionne parfaitement. Le seul problème est que c'est une application portrait. Ainsi, lorsque je fais pivoter l'appareil en mode paysage, la vidéo s'affiche toujours comme voulu, mais toutes mes étiquettes et mon interface utilisateur sont maintenant latérales.

enter image description here

Pour résoudre ce problème, je suis mise en paysage que dans le info.plist

problème est le suivant:

enter image description here

Voici mon code:

- (id)initWithFrame:(CGRect)frame 
{ 
    self = [super initWithFrame:frame]; 

    if (self) 
    { 
     self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 

     assert(self.autoresizesSubviews); 


     CGPoint layerRectCenter = CGPointMake(CGRectGetMidX(frame), 
               CGRectGetMidY(frame)); 


     // Initialization code 
     self.captureSession = [[[AVCaptureSession alloc] init] autorelease]; 

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

     // addVideoPreviewLayer 
     { 
      self.previewLayer = [[[AVCaptureVideoPreviewLayer alloc] initWithSession: self.captureSession] autorelease]; 
      self.previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill; 

      self.previewLayer.frame = CGRectMake(0, 0, 480, 300); 
      self.previewLayer.orientation = AVCaptureVideoOrientationLandscapeRight; 


      //self.previewLayer.frame = frame; 

      [self.layer addSublayer: self.previewLayer]; 
     } 

     // run! 
     [self.captureSession startRunning]; 

    } 
    return self; 
} 

Je n'arrive pas à comprendre pourquoi la vidéo est affichée sur le côté et, bien que le cadre des calques soit défini spécifiquement pour le paysage CGRectMake (0, 0, 480, 300), il sort dans l'autre sens.

+0

est AVcapturePreviewlayer enregistré dans capture d'écran? –

+0

est votre AVcapturePreviewlayer enregistré en capture d'écran vidéo ?. –

+0

je suis dans le besoin !!! –

Répondre

2

Une solution très intéressante consiste à ajouter la vue directement à la fenêtre.

Le meilleur point de le faire est dans le contrôleur de vue racine:

// need to add the capture view to the window here: can't do it in viewDidLoad as the window is not ready at that point 
- (void) viewDidAppear: (BOOL) animated 
{ 
    self.frontCamView = [[[FrontCamView alloc] 
          initWithFrame: [UIScreen mainScreen].bounds] 
         autorelease]; 

    self.view.opaque = NO; 
    self.view.backgroundColor = [UIColor clearColor]; 

    [self.view.window addSubview: self.frontCamView]; 
    [self.view.window sendSubviewToBack: self.frontCamView]; 
} 

Ensuite, la mise en œuvre de la vue de la caméra elle-même:

@interface FrontCamView () 

@property (retain) AVCaptureVideoPreviewLayer* previewLayer; 
@property (retain) AVCaptureSession* captureSession; 

@end 

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

@implementation FrontCamView 

@synthesize captureSession; 
@synthesize previewLayer; 

// - - - 

- (id)initWithFrame:(CGRect)frame 
{ 
    self = [super initWithFrame:frame]; 

    if (self) 
    { 
     self.captureSession = [[[AVCaptureSession alloc] init] autorelease]; 

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

     // addVideoPreviewLayer 
     { 
      CGRect screenRect = [UIScreen mainScreen].bounds; 

      self.previewLayer = [[[AVCaptureVideoPreviewLayer alloc] initWithSession: self.captureSession] autorelease]; 

      self.previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill; 
      self.previewLayer.frame = screenRect; 
      self.previewLayer.orientation = AVCaptureVideoOrientationPortrait;   

      [self.layer addSublayer: self.previewLayer]; 

     } 

     // run! 
     [self.captureSession startRunning]; 

    } 
    return self; 
} 

- (void) dealloc 
{ 
    [self.captureSession stopRunning]; 

    [previewLayer release], previewLayer = nil; 
    [captureSession release], captureSession = nil; 


    [super dealloc]; 
} 

@end 
Questions connexes