0

I currently have an MPMoviePlayerController with controlStyle set to MPMovieControlStyleNone.

When the video finishes playing, I want to allow the user to replay the video by touching the video.

I have set a UITapGestureRecognizer on the MPMoviePlayerController's view which is correctly calling an event handler when a MPMoviePlayerController is tapped.

However, I can only seem to obtain the MPMoviePlayerController's view through the UITapGestureRecognizer that is passed to the event handler so I can't access the actual MPMoviePlayerController object to play the video again.

I'm very new to iOS and objective-c development so this may be a silly question. Is there a way I can get a reference to the MPMoviePlayerController to start playing it again?

Here is the code used to set up the UITapGestureRecognizer:

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleMoviePlayerTap:)];
tap.numberOfTapsRequired = 1;
tap.delegate = self;
[_moviePlayer.view addGestureRecognizer:tap];

Here is the handler with nothing implemented yet:

- (void)handleMoviePlayerTap :(UITapGestureRecognizer*) tap
{
    NSLog(@"Movie player was tapped");
    // Somehow start playing the video again
}
jennafin
  • 13
  • 2
  • don't add it to `_moviePlayer.view` .. add it to its parent view. – rahul_send89 Oct 25 '14 at 07:31
  • I have a UITapGestureRecognizer for the parent view that I want to handle differently. – jennafin Oct 25 '14 at 07:34
  • ok i though `_moviePlayer` is `MPMoviePlayerController` .. depends upon how your are adding `MPMoviePlayerController` .. please check [link](http://stackoverflow.com/questions/12593542/ios-6-mpmovieplayerviewcontroller-and-presentmovieplayerviewcontrolleranimated-r) – rahul_send89 Oct 25 '14 at 07:54
  • _moviePlayer is my MPMoviePlayerController. Not sure how that link relates. Thanks – jennafin Oct 25 '14 at 08:20
  • declare `_moviePlayer` globally .. this way you can call `[_moviePlayer play]` in `handleMoviePlayerTap` .. – rahul_send89 Oct 25 '14 at 08:24
  • I have a lot of `MPMoviePlayerController`'s on the screen so need to get a reference to the correct one. I think I will just resort to checking the position of the touch and see which `MPMoviePlayerController` it is in the bounds of. Thanks – jennafin Oct 25 '14 at 08:27
  • i don't think there is way to get `MPMoviePlayerController` from its child view `MPMovieView` . you can make a invisible view on each `MPMoviePlayerController` and add tap . make use of `.tag` as a difference for each invisible view. – rahul_send89 Oct 25 '14 at 08:41

1 Answers1

0

I ended up using an NSMutableDictionary to map from the view to the MPMoviePlayerController.

jennafin
  • 13
  • 2