Domanda

Ho un problema con il MPMoviePlayerViewController: Se il controller non riesce a trovare il film al URL specificato viene visualizzata una schermata bianca e non riesco a farlo andare vicino

.

Questo è il modo di iniziare il giocatore di film:

- (void) playVideo:(NSString*)path 
{
 NSURL* url = [NSURL URLWithString:path];

 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];

 double osversion = [[[UIDevice currentDevice] systemVersion] doubleValue];
 if (osversion >= 3.2) 
 {
  mplayerVC = [[MPMoviePlayerViewController alloc] initWithContentURL:url];

  if (mplayerVC)
  {
   mplayerVC.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
   [mplayerVC.moviePlayer play];
   mplayerVC.moviePlayer.shouldAutoplay = TRUE;

  [self presentMoviePlayerViewControllerAnimated:mplayerVC];

  //[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerLoadStateChanged:) name:MPMoviePlayerLoadStateDidChangeNotification object:nil];    
  }

 }  
}

e questo è come moviePlayBackDidFinish: metodo assomiglia a questo


    - (void) moviePlayBackDidFinish:(NSNotification*)notification 
    {
     [[NSNotificationCenter  defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:nil];  

     NSError* error = [[notification userInfo] valueForKey:@"error"];
     if (error != nil)
     {
      // Movie ended with an error
      DLog(@"error=%@", error);
     }
     else 
     {
      // Movie ended successfully
     }

     [self dismissMoviePlayerViewControllerAnimated];
     SAFE_DEL(mplayerVC);
    }

Lo schermo bianco avviene solo se l'URL che punta sbagliato

È stato utile?

Soluzione

Mai ragazzi mente, ho capito.

A quanto pare nel metodo moviePlaybackDidFinish devi chiamare

[player stop];

prima di congedare il controller.

In alto, il giocatore è l'oggetto MPMoviePlayerController ottenuto in questo modo:

MPMoviePlayerController *player = [notification object];
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top