3



我制作 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

请告诉清晰的背景方式。

4

3 回答 3

13

您需要将其更改为:

moviePlayer.backgroundView.backgroundColor = [UIColor clearColor];
for(UIView *aSubView in moviePlayer.view.subviews) {
    aSubView.backgroundColor = [UIColor clearColor];
}
于 2012-08-27T14:10:39.510 回答
10

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

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

moviePlayer.backgroundView.backgroundColor = [UIColor clearColor];

moviePlayer.view.backgroundColor = [UIColor clearColor];

for(UIView *aSubView in moviePlayer.view.subviews) {
    aSubView.backgroundColor = [UIColor clearColor];
}
于 2013-05-10T05:56:28.537 回答
0

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

警告需要 IO6>= 我相信:

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

于 2013-10-18T22:18:31.467 回答