2010-03-18 18 views

回答

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沒有記錄任何有關此任務的信息。

乾杯......

+0

喜歡你的做法..!和+1這個 – Kamarshad 2012-11-01 11:43:22

+0

它不起作用,當啓用3G – hariszaman 2016-01-15 10:05:04

0

查看movieControlMode屬性。您可以設置MPMovieControlMode

MPMovieControlMode用於顯示電影播放控件的選項。

typedef enum { 
    MPMovieControlModeDefault, 
    MPMovieControlModeVolumeOnly, 
    MPMovieControlModeHidden 
} 

MPMovieControlMode;

您還可以檢查出MPMoviePlayerScalingModeDidChangeNotification

+1

我知道如何啓用控件,我在尋找的是控件出現和消失時的通知(例如,當用戶點擊屏幕時)。 – 2010-03-18 01:04:29

0

預iOS3.2
檢測 「disapierance」 很簡單:

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

檢測appierance是有點困難(也許有更好的方法) :

... 
[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 
    } 
} 
+0

我指的是在電影頂部的HUD中出現的播放器控件。這些將在移動過程中出現並消失(例如,當用戶點擊電影時)。 – 2010-09-27 17:38:08

0

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控件的標籤,因此它可以更準確地工作。

相關問題