2

如您所知,当我使用MPmoviePlayerController播放影片时,moviePlayer应在moviePlayer'view的中心显示一个activityIndi​​catorView。现在,我已将一个自定义activityIndi​​catorView放入我的程序中,我只想隐藏或移除MPMoviePlayController的activityIndi​​catorView,我可以这样做吗?隐藏MoviePlayerController中的ActivityIndi​​cator

回答

7

是的,我们可以!

我想你想要做的是在你的电影被加载时显示活动idicator,而不是当它被播放时?我只是假设并继续...在SDK 3.2及更高版本中,整个MPMoviePlayerController(和MPMoviePlayerViewController)比以前的版本好很多。如果你仍然使用MPMoviePlayerController,你可以考虑切换到MPMoviePlayerViewController(它基本上是一个包装MPMoviePlayerController对象的UIView子类)。无论如何,为了显示和隐藏你的UIActivityindicator视图,我建议你挂载到MPMoviePlayerController在负载或playstatus更改时发送的通知。

其中的几个是:

MPMoviePlayerPlaybackStateDidChangeNotification 
MPMoviePlayerLoadStateDidChangeNotification 

所以你挂接到这些事件这样做:

[[NSNotificationCenter defaultCenter] addObserver: self 
              selector: @selector(loadStateChanged:) 
               name: MPMoviePlayerLoadStateDidChangeNotification 
               object: moviePlayerViewController.moviePlayer]; 

[[NSNotificationCenter defaultCenter] addObserver: self 
              selector: @selector(playBackStateChanged:) 
               name: MPMoviePlayerPlaybackStateDidChangeNotification 
               object: moviePlayerViewController.moviePlayer]; 

和您的处理程序中(playBackStateChangedloadStateChanged

你可以做这样的事情:

-(void)playBackStateChanged:(id)sender 
{ 
    MPMoviePlaybackState playbackState = [moviePlayerViewController.moviePlayer playbackState]; 

    switch (playbackState) { 

     case MPMoviePlaybackStateStopped : 


      break; 

     case MPMoviePlaybackStatePlaying : 
      [yourActivityIndicatorView stopAnimating]; 
      break; 

     case MPMoviePlaybackStateInterrupted : 
      [yourActivityIndicatorView startAnimating]; 
      break; 
    } 
} 

确保“hidesWhenStopped”(或类似)你IndicatorView的属性被设置为yes(如果你这样做,你不必关心和隐藏取消隐藏控制。

其余的很简单,只需在您的MPMovieViewController视图中添加您的activityIndi​​catorView ontop即可。

希望我能帮助
欢呼
SAM

+0

我这样做,我只想让moviePlayerViewController的activeIndicator从不显示,因为我已经被自己 – ben 2010-07-10 01:33:44

+0

阿添加activeIndicator我想我明白你现在。解决办法是隐藏你的播放器,直到Movieplayer的Loadstate等于MPMovieLoadStatePlayable,然后再次取消播放器。同时您可以显示您的自定义加载程序。 – samsam 2010-07-14 09:16:06

相关问题