4

In one of my application, I don't want to show any video controllers. But I need to get the touch on the media player view. I need to do some other action on touch on the movie player. How can I implement that. Please help

Thanks in advance.

2 Answers2

5

You can always attach a UITapGestureRecognizer to the view and handle the taps.

UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
[moviePlayer.view addGestureRecognizer:tap];
[tap release];

And handle the tap in handleTap:

- (void)handleTap:(UITapGestureRecognizer *)gesture {
    // Do some other action as intended.
}

Of course this works only on iOS 3.2 and later.

Deepak Danduprolu
  • 44,595
  • 12
  • 101
  • 105
  • Thank you!!... I tried TapGuesterRecognizer but made a small mistake..Thank you for correcting me :) – Sagar S. Kadookkunnan Jun 17 '11 at 11:01
  • Is that possible to do in iOS 3 onwards?. I mean other than GuesterRecognizer. Or do I need to subclass MoviePlayerController to get touch events?. – Sagar S. Kadookkunnan Jun 17 '11 at 11:13
  • @cherukkayi Prior to 3.2, the controller took the entire screen and managed the view itself. You can't change the `controlStyle` attribute prior to 3.2 either. – Deepak Danduprolu Jun 17 '11 at 11:17
  • 1
    @Deepak, what you state in your last comment is mostly incorrect. Yes, UIGestureRecognizer did not exist prior to iOS 3.2 (and even within 3.2 it was kinda beta). For the rest, MPMoviePlayerController was allways allowing the removal of the controls (settings controlStyle), it just did not support embedded playback. The solution for recognizing taps prior to 3.2 is adding a custom view on top of MPMoviePlayerController and trapping touches. – Till Jun 19 '11 at 15:09
  • I got your last statement. But there wasn't a `controlStyle` property, was it? – Deepak Danduprolu Jun 19 '11 at 15:19
  • Hi All, I am trying to get single click over a movieplayer view. I am able to capture double tap event using UITapGestureRecognizer. But I am not getting single tap using the same. Any ideas?. Please help. – Sagar S. Kadookkunnan Jun 20 '11 at 13:45
  • @SagarS.Kadookkunnan : I am facing same issue as you means only double tap working. Could you address your issue? – BaSha May 13 '15 at 11:28
  • @BaSha [http://stackoverflow.com/users/1840935/basha] - Please check the first answer given in the following link, http://stackoverflow.com/questions/7487182/mpmovieplayercontrollers-view-does-not-recognize-touch – Sagar S. Kadookkunnan May 20 '15 at 11:19
0

You can also use this delegate method of UIGestureRecognizer.

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch;
Vikas S Singh
  • 1,748
  • 1
  • 14
  • 29
Mohit Gaur
  • 69
  • 11