Search code examples
iosobjective-cvideompmovieplayercontrolleruitapgesturerecognizer

How to make MPMoviePlayer show Controls after a tap?


This is my code and it does not work on tap. This is how I see my code: The control style of the player is initially hidden. The player view has a tap gesture recogniser in it. When it taps, I want to show the Controls appear :

- (void)viewDidLoad {

    _player = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
    [_player.view setFrame:CGRectMake(0, 0, 540, 250)];
     [self.view addSubview:_player.view];
    _player.view.center = self.view.center;

    //Control style is None
    _player.controlStyle = 0;

    //Gesture
     tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
    [_player.view addGestureRecognizer:tap];
    tap.numberOfTapsRequired = 1;
    _player.scalingMode = 2;
    [_player prepareToPlay];
    [_player shouldAutoplay];

}

- (void)handleTap:(UITapGestureRecognizer *)gesture {
    // ControlStyle changed to ShowEmbedded
        _player.controlStyle = 1;
}

I have added the tap recogniser in the view of the player area, it should show but sadly it does not. I have added the super viewDidLoad in my actual code. That is not the problem.


Solution

  • Make a button. When the button is tapped, the video should be paused. Then change the control style within. The user then has to click the to see the controls.

    - (IBAction)showControls:(id)sender {
        [_player pause];
        _player.controlStyle =  MPMovieControlStyleEmbedded;   
    }