How to detect when iPhone MPMoviePlayer controls appear/disappear?
Asked Answered
B

4

5

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?

Bjork answered 18/3, 2010 at 0:17 Comment(0)
S
10

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

Starr answered 18/3, 2011 at 14:35 Comment(1)
like your approach ..!! and +1 for thisLuciana
T
1

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.

Transpontine answered 6/1, 2016 at 16:50 Comment(1)
God bless you sir!Vas
C
0

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

Clapperclaw answered 18/3, 2010 at 0:27 Comment(1)
I know how to enable the controls, what I'm looking for is a notification when the controls appear and disappear (for instance, when the user taps the screen).Bjork
C
0

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
  }
}
Conjecture answered 26/9, 2010 at 20:22 Comment(1)
I'm referring to the player controls that appear in a HUD over top of the movie. These will appear and disappear while the move is playing (for instance, when the user taps on the movie).Bjork

© 2022 - 2024 — McMap. All rights reserved.