Iphone 播放错误时关闭MPMoviePlayerViewController

Iphone 播放错误时关闭MPMoviePlayerViewController,iphone,dismiss,mpmovieplayer,mpmoviewcontroller,Iphone,Dismiss,Mpmovieplayer,Mpmoviewcontroller,我对mpmovieplayervewcontroller有一个问题:如果控制器在指定的URL上找不到电影,它会显示一个白色屏幕,我无法让它关闭 以下是我启动电影播放器的方式: - (void) playVideo:(NSString*)path { NSURL* url = [NSURL URLWithString:path]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieP

我对mpmovieplayervewcontroller有一个问题:如果控制器在指定的URL上找不到电影,它会显示一个白色屏幕,我无法让它关闭

以下是我启动电影播放器的方式:

- (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];    
  }

 }  
}
这就是moviePlayBackDidFinish:方法的样子


    - (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);
    }

只有当URL指向错误时才会出现白色屏幕

伙计们,别介意,我发现了

显然在电影回放中,你必须调用didfish方法

[player stop];
在解除控制器之前

上面,player是MPMoviePlayerController对象,如下所示:

MPMoviePlayerController *player = [notification object];