0

When I click on a picture, I show a pop-up with a video in it. In that pop up, a video is launching automatically. The problem is that I don't have interactivity with the video (play, pause, etc...). So for now, I found the way to loop it with the AVPlayerItemDidPlayToEndTimeNotification but I would like the user has the capability to play/pause. Here is my code :

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(itemDidFinishPlaying:) name:AVPlayerItemDidPlayToEndTimeNotification object:player];

    NSURL *url = [NSURL fileURLWithPath:mediaPath];
    player = [[AVPlayer alloc] initWithURL: url];
    controller = [[AVPlayerViewController alloc] init];
    controller.player = player;
    controller.delegate = self;
    controller.showsPlaybackControls = YES;

    UIImageView *popView = [[[[[[NSBundle mainBundle] loadNibNamed:mediaType owner:self options:nil] objectAtIndex:0] viewLoadedFromXib] subviews] objectAtIndex:0];
    [controller.view setFrame:CGRectMake(0, 0, 850, 600)];
    [popView addSubview:controller.view];

    [player play];

I precise that when I click on the video, the bar with the pause video appears below, but when I click on the button, nothing happens.

1ST EDIT: It seems that there is a AVTouchIgnoringView that has been added automatically by the AVPlayerViewController. It seems that there is a link with UserInteraction... But I try to put it to YES without success. May be I don't do it for the good view. Any ideas ?

enter image description here

2ND EDIT : this is the setFrame that adds the AVTouchIgnoringView. So do you know how can I change the size of the frame without it adding automatically that AVTouchIgnoringView ?

ΩlostA
  • 2,501
  • 5
  • 27
  • 63
  • Is there any reason you aren't just presenting the AVPlayerViewController as a modal view? I wouldn't recommend showing it like this. Use the presentViewController:animated: method on the view controller that is responsible for all this. Check out the section on presenting view controllers here https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIViewController_Class/ – GCBenson Jun 20 '16 at 08:59
  • I would like to present it as a pop up because of the presentation. I have a map, and I want to show a video in a pop up, with the map behind. The customer wants the map always showed behind (on an ipad). I don't understand why it is not working as when I click on the video two times, there is a little zoom, so it means that I have the hand on it, but I cannot pause the video with the bar below. Very strange... – ΩlostA Jun 20 '16 at 09:03
  • Have a look at UIPopoverPresentaionController, it will handle properly presenting a view controller as a popover on iPad, but full screen on iPhone. Theres plenty of online resources for it, so no need for me to post anything here. – GCBenson Jun 20 '16 at 09:18
  • I created a pretty popover with a pretty animation so I would like to use it. Thank you for your attention. I will wait if someone has an idea. – ΩlostA Jun 20 '16 at 09:21
  • I progress. It is the setFrame that produce that AVTouchIgnoringView and many others supplementary views... The soluction in a few minutes I hope. – ΩlostA Jun 20 '16 at 13:12

2 Answers2

1

First, I think that the UIImageView is not correct as you put a video in it, so I advise you to change in UIView.

        UIView *popView = [[[[[[NSBundle mainBundle] loadNibNamed:mediaType owner:self options:nil] objectAtIndex:0] viewLoadedFromXib] subviews] 

Second, I think that you may have user interactivity with the video. Try a bigger size to display the bottom bar with controls.

//video resize

 controller.view.frame = CGRectMake(0, 0, 900, 600);//for example
dt dino
  • 1,194
  • 6
  • 19
  • It is magic, it works. I was so obsessed with the userInteractivity, it was just the frame size problem! (and you're right for the imageView, I made a mistake). Thx. – ΩlostA Jun 20 '16 at 16:18
0

In my case touch on the AVPlayerViewController view was ignored because of the gesture recognizer on one of its superviews. Mentioned recognizer was returning NO from the method: canBePreventedByGestureRecognizer:.

Adding an exception for the recognizer owned by AVPlayerViewController fixed the issue and the UI is usable again.

karolszafranski
  • 702
  • 8
  • 17