MPMoviePlayerController存在黑色背景
问题描述:
我制作iOS应用程序。
我使用MPMoviePlayerController,但显示黑色背景。
我觉得这个问题可以通过这个URL解决,但是我不明白使用方法。
MPMoviePlayerController background color won't stick
我的代码是这样的。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
请告诉清楚背景的方式。
答
您需要将其更改为:
moviePlayer.backgroundView.backgroundColor = [UIColor clearColor];
for(UIView *aSubView in moviePlayer.view.subviews) {
aSubView.backgroundColor = [UIColor clearColor];
}
+0
正试图解决这一个一段时间,谢谢!你是男人:D – SuperKevin
答
设置背景图的颜色单独对我没有工作。
我认为视图背景颜色也应该改变。我添加了一行代码,现在它很好。整个视频背景现在都是透明的。 :)谢谢@Jordi
moviePlayer.backgroundView.backgroundColor = [UIColor clearColor];
moviePlayer.view.backgroundColor = [UIColor clearColor];
for(UIView *aSubView in moviePlayer.view.subviews) {
aSubView.backgroundColor = [UIColor clearColor];
}
当使用'[UIColor redColor]'时会发生什么,它会改变颜色吗?在这种情况下,我认为'clearColor'不起作用。 – skram