13

Quiero mostrar un MPMoviePlayerController en un controlador de vista y dejar que el usuario alternar a pantalla completa con los controles predeterminados, como la aplicación de YouTube. Estoy usando el siguiente código en un ejemplo escueto:MPmoviePlayerController quirk de pantalla completa en el iPad

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    self.player = [[MPMoviePlayerController alloc] init]; 
    self.player.contentURL = theURL; 
    self.player.view.frame = self.viewForMovie.bounds; 
    self.player.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 
    [self.viewForMovie addSubview:player.view]; 
    [self.player play]; 
} 

Esto funciona bien hasta que el usuario hace que el vídeo a pantalla completa, hace girar el dispositivo y toca en la pantalla. La barra de estado se muestra en la posición incorrecta, como se muestra en la captura de pantalla a continuación.

screenshot

estoy trabajando con la plantilla Tab barra de aplicaciones para iPad. Solo agregué el viewDidLoad arriba, las variables de vista y un UIView en el XIB para mostrar el reproductor de películas.

¿Qué estoy haciendo mal?

+0

que estoy experimentando el mismo problema. Todavía no hay solución? – samvermette

+0

Yo también. Alguien tiene esto funcionando? – V1ru8

+0

¿Recibió alguna respuesta? – Jingwei

Respuesta

2

¿Debe shouldAutorotateToInterfaceOrientation: interfaceOrientation devolver YES para todas las orientaciones admitidas?

 
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    return YES; 
} 

Si proporcionó más de su código ayudaría.

+0

Sí. El único código que he agregado al proyecto es viewDidLoad arriba y, por supuesto, viewForMovie en XIB. Es la aplicación de barra de pestañas predeterminada para iPad. – hpique

1

¿Está utilizando el constructor de interfaz para su UI? de ser así, asegúrese de establecer la orientación de la vista en 'paisaje' en el inspector de atributos de vista.

+0

Ahora falla en la otra orientación. – hpique

1

Tuve el mismo problema, solo pasé medio día clasificándolo. Con el iPad en orientación vertical, cada vez que comencé un video con el código de muestra (o cualquiera que pude encontrar en la red), el video y la barra de control se formateaban para el retrato y, por lo tanto, en todo el lugar de la pantalla.

De todos modos, el siguiente funciona para mí.

/* Call the code like below: 
     int iLandscape; 
     if(newOrientation==UIInterfaceOrientationLandscapeLeft || newOrientation==UIInterfaceOrientationLandscapeRight) 
      iLandscape=1; 

     [self PlayVideo:iLandscape fullscreen:1] 
    */ 
     ////////////////////////////////////////////////////////////////////////// 
     - (void)PlayVideo:(int)iLandscape fullscreen:(int)iFullScreen 
     { 
      NSString *url = [[NSBundle mainBundle] pathForResource:@"myvideofile" ofType:@"m4v"]; 

     if(iFullScreen==0) 
     { 
      MPMoviePlayerController *player2 = 
       [[MPMoviePlayerController alloc] 
        initWithContentURL:[NSURL fileURLWithPath:url]]; 

      [[NSNotificationCenter defaultCenter] 
       addObserver:self 
        selector:@selector(movieFinishedCallback:) 
         name:MPMoviePlayerPlaybackDidFinishNotification 
        object:player2]; 

      //---play partial screen--- 
      player2.view.frame = CGRectMake(0, 0, m_iScreenWidth, m_iScreenHeight); 
      [self addSubview:player2.view]; 
      //---play movie--- 
      [player2 play]; 
     } 
     else 
     { 
      MPMoviePlayerViewController *playerViewController = [[MPMoviePlayerViewController alloc] 
       initWithContentURL:[NSURL fileURLWithPath:url]]; 

      [[NSNotificationCenter defaultCenter] 
       addObserver:self 
        selector:@selector(movieFinishedCallback:) 
         name:MPMoviePlayerPlaybackDidFinishNotification 
        object:[playerViewController moviePlayer]]; 

      if(iLandscape) 
      { 
       playerViewController.view.frame = CGRectMake(0, 0, m_iScreenWidth, m_iScreenHeight); 
      } 
      [self addSubview:playerViewController.view]; 
      //play movie 
      MPMoviePlayerController *player = [playerViewController moviePlayer]; 
      player.scalingMode=MPMovieScalingModeAspectFit; 
      [player play]; 
     } 
    } 


    ////////////////////////////////////////////////////////////////////////// 
    - (void) movieFinishedCallback:(NSNotification*) aNotification 
    { 
     MPMoviePlayerController *player = [aNotification object]; 
     [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:player];  
     [player autorelease];  
     [player.view removeFromSuperview]; 
    } 
0

¿Has resuelto este problema?

[[UIApplication sharedApplication] setStatusBarOrientation:UIDeviceOrientationPortrait animated:NO]; 

Este código podría ayudarlo.

3

Sí, estoy experimentando este problema también. Definitivamente parece ser un error en el MPMoviePlayerController.

La solución me he decidido por mi solicitud es que la mera corrección de la barra de estado cuando me salir del modo de pantalla completa:

- (void)playerDidExitFullscreen:(NSNotification *)notification { 
    MPMoviePlayerController *moviePlayer = (MPMoviePlayerController *) notification.object; 

    if (moviePlayer == self.player) { 
     UIApplication *app = [UIApplication sharedApplication]; 
     if (app.statusBarOrientation != self.interfaceOrientation) { 
      [app setStatusBarOrientation:self.interfaceOrientation animated:NO]; 
     } 
    } 
} 

Esto no soluciona el problema, mientras que en el modo de pantalla completa, pero lo hace arreglarlo después

Nota por supuesto que necesita la función que se añade a la notificación:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerDidExitFullscreen:) name:MPMoviePlayerDidExitFullscreenNotification object:nil]; 
0

encontrado.

Tuve el mismo problema: esto es lo que hice. Sugeriría agregar el código a su proyecto uno por uno para ver exactamente cómo funciona.

Primero - Puse las cosas en modo retrato.

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO]; 

Luego empujé la película hacia abajo en la barra de estado.Nota - esto asume que el vídeo tiene una relación de aspecto de 4x3

theVideo = [[MPMoviePlayerController alloc] initWithContentURL: [NSURL fileURLWithPath : path]]; 
float aspectRatio = (3.0f/4.0f); 
float theMovieHeight = [self view].bounds.size.width * aspectRatio; 
[[theVideo view] setFrame:(CGRectMake(0, [self view].bounds.size.height - theMovieHeight, [self view].bounds.size.width, theMovieHeight))]; 

Luego, en el lugar donde se inicia la aplicación (en mi proyecto, que está en la función didFinishLaunchingWithOptions) - de todos modos, sólo tiene acceso a la objeto de ventana

float aspectRatio = (3.0f/4.0f); 
float theMovieHeight = self.window.bounds.size.width * aspectRatio; 
float theSpaceAboveTheMovie = self.window.bounds.size.height - theMovieHeight; 
float whereTheMovieShouldBeCentered = (self.window.bounds.size.height - theMovieHeight)/2; 

CGAffineTransform theTransform = CGAffineTransformMakeTranslation(0,0); 

theTransform = CGAffineTransformScale(theTransform, 1.0f/aspectRatio, 1.0f/aspectRatio); 
theTransform = CGAffineTransformTranslate(theTransform, -whereTheMovieShouldBeCentered, 0); 
theTransform = CGAffineTransformRotate(theTransform, M_PI/2); 
theTransform = CGAffineTransformTranslate(theTransform, 0, -theSpaceAboveTheMovie); 

[self.window setTransform:theTransform]; 

Recuerde que las transformaciones afines se realizan en orden inverso. Así que si usted quiere ver lo que cada archivo de transformación está haciendo (yo sugeriría que debería), comente los tres primeros

Aquí debería ver la película de la barra y el estado centrada en la página

// theTransform = CGAffineTransformScale(theTransform, 1.0f/aspectRatio, 1.0f/aspectRatio); 
// theTransform = CGAffineTransformTranslate(theTransform, -whereTheMovieShouldBeCentered, 0); 
// theTransform = CGAffineTransformRotate(theTransform, M_PI/2); 
    theTransform = CGAffineTransformTranslate(theTransform, 0, -theSpaceAboveTheMovie); 

Entonces, el primer dos

Aquí debería ver la película de la barra y el estado de gira y ya no se centra

// theTransform = CGAffineTransformScale(theTransform, 1.0f/aspectRatio, 1.0f/aspectRatio); 
// theTransform = CGAffineTransformTranslate(theTransform, -whereTheMovieShouldBeCentered, 0); 
    theTransform = CGAffineTransformRotate(theTransform, M_PI/2); 
    theTransform = CGAffineTransformTranslate(theTransform, 0, -theSpaceAboveTheMovie); 

Aquí debería ver que gira y se centra

// theTransform = CGAffineTransformScale(theTransform, 1.0f/aspectRatio, 1.0f/aspectRatio); 
    theTransform = CGAffineTransformTranslate(theTransform, -whereTheMovieShouldBeCentered, 0); 
    theTransform = CGAffineTransformRotate(theTransform, M_PI/2); 
    theTransform = CGAffineTransformTranslate(theTransform, 0, -theSpaceAboveTheMovie); 

Y con todos ellos, se gira y pantalla completa

Puede descargar mi código de ejemplo here.

0

probar este

- (void)willEnterFullscreen:(NSNotification*)notification { 
    NSLog(@"willEnterFullscreen"); 

    [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO]; 
    } 

- (void)enteredFullscreen:(NSNotification*)notification { 
    NSLog(@"enteredFullscreen"); 
} 

- (void)willExitFullscreen:(NSNotification*)notification { 
    NSLog(@"willExitFullscreen"); 

    [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO]; 


} 

- (void)exitedFullscreen:(NSNotification*)notification { 
    NSLog(@"exitedFullscreen"); 

    [[NSNotificationCenter defaultCenter] removeObserver:self]; 
} 
Cuestiones relacionadas