的MPMoviePlayerController存在黑色背景(MPMoviePlayerContro

2019-09-17 22:56发布



我做iOS应用。

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

我觉得这个问题可以通过这个网址解决,但我不明白的使用方式。
的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

请转告背景清晰的方式。

Answer 1:

您需要将其更改为:

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


Answer 2:

单独设置背景图的颜色并没有为我工作。

我认为,观察背景颜色也应该改变。 我加的一行代码,现在炒菜锅的罚款。 整个视频的背景,现在是透明的。 :)谢谢@Jordi

moviePlayer.backgroundView.backgroundColor = [UIColor clearColor];

moviePlayer.view.backgroundColor = [UIColor clearColor];

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


Answer 3:

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

警告需要IO6> =我相信:

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



文章来源: MPMoviePlayerController existed black background