Search code examples
iphonempmovieplayercontrollermpmovieplayer

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?


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