xcode MPMoviePlayerController 存在黑色背景

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10956589/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 00:32:29  来源:igfitidea点击:

MPMoviePlayerController existed black background

iphoneobjective-ciosxcode

提问by Osushi



I make iOS app.

I use MPMoviePlayerController, but this shows black background.

I think this problem can solve by this URL, but I can't understand use way.
MPMoviePlayerController background color won't stick

My code is this.



我做iOS应用。

我使用 MPMoviePlayerController,但这显示黑色背景。

我认为这个问题可以通过这个 URL 解决,但我无法理解使用方式。
MPMoviePlayerController 背景颜色不会粘住

我的代码是这样的。

NSString *path = [[NSBundle mainBundle] pathForResource:@"movie_files" ofType:@"m4v"];
NSURL *videoURL = [NSURL fileURLWithPath:path];

moviePlayer =  [[MPMoviePlayerController alloc]
                initWithContentURL:videoURL];

//setting
moviePlayer.scalingMode =MPMovieScalingModeAspectFit;
moviePlayer.controlStyle=MPMovieControlStyleDefault;
moviePlayer.shouldAutoplay=NO;
[moviePlayer.view setFrame:CGRectMake(20, 20, 280, 200)];    

//notification
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(moviePlayBackDidFinish:)
                                             name:MPMoviePlayerPlaybackDidFinishNotification
                                           object:moviePlayer];

//clearColor
UIView *subV =[[UIView alloc]init];
for(subV in moviePlayer.backgroundView.subviews) {
    subV.backgroundColor = [UIColor clearColor];
}
[moviePlayer.view addSubview:subV];    
[self.view addSubview:moviePlayer.view];
//show white screen

Please tell the clear background way.

请告诉清楚的背景方式。

回答by Jordi

You need to change it to:

您需要将其更改为:

moviePlayer.backgroundView.backgroundColor = [UIColor clearColor];
for(UIView *aSubView in moviePlayer.view.subviews) {
    aSubView.backgroundColor = [UIColor clearColor];
}

回答by Abhijith

Setting Background view's color alone didn't work for me.

单独设置背景视图的颜色对我不起作用。

I think the view background color should also be changed. I added one more line of code and now it woks fine. The entire video background is transparent now. :) Thanks @Jordi

我认为视图背景颜色也应该改变。我又添加了一行代码,现在一切正常。整个视频背景现在是透明的。:) 谢谢@Jordi

moviePlayer.backgroundView.backgroundColor = [UIColor clearColor];

moviePlayer.view.backgroundColor = [UIColor clearColor];

for(UIView *aSubView in moviePlayer.view.subviews) {
    aSubView.backgroundColor = [UIColor clearColor];
}

回答by yeahdixon

another option is to hide the video player and then show it when it is ready to display

另一种选择是隐藏视频播放器,然后在准备好显示时显示它

caveat needs IO6>= i believe:

警告需要 IO6>= 我相信:

https://stackoverflow.com/a/19459855/401896

https://stackoverflow.com/a/19459855/401896