Question

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?

Was it helpful?

Solution

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 ...

OTHER TIPS

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.

Look into the movieControlMode property. You can set the MPMovieControlMode

MPMovieControlMode Options for displaying movie playback controls.

typedef enum {
   MPMovieControlModeDefault,
   MPMovieControlModeVolumeOnly,
   MPMovieControlModeHidden
} 

MPMovieControlMode;

You can also check out MPMoviePlayerScalingModeDidChangeNotification

pre iOS3.2
to detect "disapierance" is easy:

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

to detect appierance is bit harder (maybe there is better way):

...
[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
  }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top