如何检测iPhone MPMoviePlayer控件何时出现/消失?

时间:2010-03-18 00:17:22

标签: iphone mpmovieplayercontroller mpmovieplayer

我正在尝试在MPMoviePlayerController视图(OS 2.x及更高版本)中的标准快退/播放/转发控件的左侧和右侧添加自定义按钮。我已经想出如何将它们添加到播放器窗口,但它们始终可见。有没有办法检测标准控件何时出现和消失?

4 个答案:

答案 0 :(得分:10)

好的,明白了,做到这样:

BOOL controlsVisible = NO;
for(id views in [[_moviePlayer view] subviews]){
 for(id subViews in [views subviews]){
   for (id controlView in [subViews subviews]){
     controlsVisible = ([controlView alpha] <= 0.0) ? (NO) : (YES);
   }
  }
}
NSLog(@"player controls are visible: %d", controlsVisible);

_movePlayer 是您的播放器实例。 在最深的循环中,如果控件被隐藏, MPFullScreenVideoOverlay 视图实例将具有alpha == 0.0,如果显示控件,则为alpha 1.0。 您可以添加观察者并根据需要触发。我知道它并不优雅,但它对我有用,因为Apple没有记录任何有关此任务的内容。

干杯......

答案 1 :(得分:1)

cybercow的答案是正确的,只需添加一些修改就可以使答案更准确。

BOOL controlsVisible = NO;
for(id views in [[self.moviePlayerViewController view] subviews])
{
   for(id subViews in [views subviews])
   {
      for (id controlView in [subViews subviews])
      {
          if ([controlView isKindOfClass:[UIView class]] && ((UIView*)controlView).tag == 1004)
          {
             controlsVisible = ([controlView alpha] <= 0.0) ? (NO) : (YES)               
          }
      }

   }
}

我改变了最内圈。实际上1004是MPMoviePlayer控件的标签,因此它可以更准确地工作。

答案 2 :(得分:0)

查看movieControlMode属性。您可以设置MPMovieControlMode

MPMovieControlMode用于显示电影播放控件的选项。

typedef enum {
   MPMovieControlModeDefault,
   MPMovieControlModeVolumeOnly,
   MPMovieControlModeHidden
} 

MPMovieControlMode;

您还可以查看MPMoviePlayerScalingModeDidChangeNotification

答案 3 :(得分:0)

iOS3.2之前
检测“失望”很容易:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayerController];

检测适用性有点难度(也许有更好的方法):

...
[moviePlayerController play];
mainTimer = [NSTimer scheduledTimerWithTimeInterval:1/100 target:self selector:@selector(tick) userInfo:nil repeats:YES];

- (void)tick {
  if( [[[UIApplication sharedApplication] windows] count] < 2 ) return;

  moviePlayerWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
  if( moviePlayerWindow ){
    [mainTimer invalidate], mainTimer=nil;
    // here you have moviePlayerWindow
  }
}