我制作iOS应用程序。
我使用MPMoviePlayerController,但这显示黑色背景
我认为这个问题可以通过这个URL解决,但我无法理解使用方式
MPMoviePlayerController background color won't stick
我的代码就是这个。
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
请告诉明确的背景方式。
答案 0 :(得分:13)
您需要将其更改为:
moviePlayer.backgroundView.backgroundColor = [UIColor clearColor];
for(UIView *aSubView in moviePlayer.view.subviews) {
aSubView.backgroundColor = [UIColor clearColor];
}
答案 1 :(得分:10)
单独设置背景视图的颜色对我来说不起作用。
我认为视图背景颜色也应该改变。我添加了一行代码,现在它很好用。整个视频背景现在都是透明的。 :)谢谢@Jordi
moviePlayer.backgroundView.backgroundColor = [UIColor clearColor];
moviePlayer.view.backgroundColor = [UIColor clearColor];
for(UIView *aSubView in moviePlayer.view.subviews) {
aSubView.backgroundColor = [UIColor clearColor];
}
答案 2 :(得分:0)
另一种选择是隐藏视频播放器,然后在准备好显示时显示它
警告需要IO6> =我相信: