Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect when iPhone MPMoviePlayer controls appear/disappear?

I'm trying to add custom buttons to the left and right of the standard rewind/play/forward controls in an MPMoviePlayerController view (OS 2.x and up). I've figured out how to add them to the player window, but they're always visible. Is there a way to detect when the standard controls appear and disappear?

like image 606
Mark Smith Avatar asked Mar 18 '10 00:03

Mark Smith


2 Answers

Ok, got it, make like this:

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);

Where _movePlayer is your instance of the player. In the deepest loop, the MPFullScreenVideoOverlay view instance will have alpha == 0.0 if the controls are hidden, or alpha 1.0 if the controls are shown. You can add an observer and fire things as needed. I know is not elegant but it works for me, as Apple has not documented anything regarding this task.

Cheers ...

like image 187
cybercow Avatar answered Oct 23 '22 17:10

cybercow


cybercow's answer is right just have to add little modification to make the answer more accurate.

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)               
          }
      }

   }
}

i changed the most inner loop. Actually 1004 is the tag of MPMoviePlayer controls so it will work more accurately.

like image 39
Abuzar Amin Avatar answered Oct 23 '22 17:10

Abuzar Amin