在播放错误时关闭MPMoviePlayerViewController [英] Dismiss MPMoviePlayerViewController on play error

查看:138
本文介绍了在播放错误时关闭MPMoviePlayerViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的MPMoviePlayerViewController有问题:如果控制器无法在指定的网址找到电影,则会显示一个白色的屏幕,我无法将其关闭。

I have a problem with the MPMoviePlayerViewController: If the controller can't find the movie at the specified URL it displays a white screen and I can't make it go close.

这就是我启动电影播放器​​的方式:

This is how I start the movie player:

- (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:方法看起来像这样

and this is how moviePlayBackDidFinish: method looks like this


    - (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指向错误时才会出现白屏

The white screen only happens if the URL is pointing wrong

推荐答案

别介意我,我想通了。

显然在moviePlaybackDidFinish方法中你必须致电

Apparently in the moviePlaybackDidFinish method you have to call

[player stop];

以上,player是这样获得的MPMoviePlayerController对象:

Above, player is the MPMoviePlayerController object obtained like this:

MPMoviePlayerController *player = [notification object];

这篇关于在播放错误时关闭MPMoviePlayerViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆