2012-06-08 114 views
3



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

請告訴清楚背景的方式。

+0

當使用'[UIColor redColor]'時會發生什麼,它會改變顏色嗎?在這種情況下,我認爲'clearColor'不起作用。 – skram

回答

13

您需要將其更改爲:

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

正試圖解決這一個一段時間,謝謝!你是男人:D – SuperKevin

10

設置背景圖的顏色單獨對我沒有工作。

我認爲視圖背景顏色也應該改變。我添加了一行代碼,現在它很好。整個視頻背景現在都是透明的。 :)謝謝@Jordi

moviePlayer.backgroundView.backgroundColor = [UIColor clearColor]; 

moviePlayer.view.backgroundColor = [UIColor clearColor]; 

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

line「moviePlayer.backgroundView.backgroundColor = [UIColor clearColor];」 是多餘的:backgroundView是moviewPlayer.view的子視圖,因此當您在「for」循環中遍歷子視圖時,顏色會發生變化。謝謝。 – SSemashko

+0

@Scarmysun,我不得不包括它。 – Antzi