Claudio Claudio - 5 months ago 45
Objective-C Question

I don't have interactivity with the video player when I put it in a pop-up

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 ?

Answer

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