Adding a view on top of a MPMoviePlayerController

2019-02-27 12:16发布

I have a MPMoviePlayerController that plays fullscreen. Then I want to add a UIButton above the movie, but it doesn't show up.

I have already tried inserting the view above the movie view like this:

mpc =[[MPMoviePlayerController alloc]initWithContentURL:url];
[mpc setMovieSourceType:MPMovieSourceTypeFile];   

[self.view addSubview:mpc.view];
**[self.view insertSubview:self.backButton aboveSubview:mpc.view];**

[mpc setFullscreen:YES];

mpc.controlStyle = MPMovieControlStyleNone;

[mpc play];

And I have also tried adding the subview to the movie controller view, like I read in a similar question:

**[mpc.view addSubview:self.backButton];**
[self.view addSubview:mpc.view];

When I log the list of subviews I always get the button in the last position, after the MPMovieView and the MPSwipable view, but it doesn't show up.

EDIT:

I've been able to work it around by disabling [mpc setFullscreen:YES] and setting the frame of the movie's view to the bounds of the parent view and setting an aspect-fill scaling mode. Not the cleanest solution I guess, but it works for me.

mpc.view.frame = CGRectMake(self.view.bounds.origin.x, self.view.bounds.origin.y, self.view.bounds.size.width, self.view.bounds.size.height);

UIButton *myButton = [[UIButton alloc]initWithFrame:CGRectMake(100, 500, 100, 100)];

myButton.backgroundColor = [UIColor blueColor];

mpc.controlStyle = MPMovieControlStyleNone;
mpc.scalingMode = MPMovieScalingModeAspectFit;

[self.view addSubview:mpc.view];

[self.view addSubview:myButton];

[mpc prepareToPlay];

1条回答
The star\"
2楼-- · 2019-02-27 12:50

Add your button over the MPMoviePlayerController as you wrote:

[mpc.view addSubview:self.backButton]

Maybe your button is hidden or nil. Try to set your player:

mpc.controlStyle = MPMovieControlStyleFullscreen;

Anyway, I do it like this:

 MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] init];
 mp.controlStyle = MPMovieControlStyleFullscreen;
 UIButton *btnInfo = [[UIButton alloc] initWithFrame:your_frame];
 [mp.view addSubview:btnInfo];

Anyway, don't use [mpc play]; you better use [mpc prepareToPlay]; (Performance issues)

查看更多
登录 后发表回答