在播放错误时关闭MPMoviePlayerViewController

问题描述 投票:4回答:1

我有一个MPMoviePlayerViewController的问题:如果控制器无法在指定的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指向错误时才会出现白屏

iphone dismiss mpmovieplayer mpmoviewcontroller
1个回答
3
投票

没关系,我想通了。

显然,你必须调用moviePlaybackDidFinish方法

[player stop];

在解雇控制器之前。

上面,播放器是这样获得的MPMoviePlayerController对象:

MPMoviePlayerController *player = [notification object];
© www.soinside.com 2019 - 2024. All rights reserved.