2012-06-15 49 views
1

我有tabBarViewController其中包含幾個頁面,和一個loginViewController。我使用[窗口addSubView:]添加視圖。MPMoviePlayerController在全屏問題(顯示空白黑屏)

當我需要播放全屏視頻時,我必須刪除窗口中的所有視圖才能顯示視頻,否則,它只是一個黑屏。當視頻停止/完成/退出時,我必須手動將子視圖添加回窗口。

我知道這是做錯的一種方式。如果我沒有這樣做,當視頻切換到全屏時,它將顯示在其他視圖背面的根窗口視圖中。

請給出一些建議。謝謝。

下面是我的代碼:

-(void)playMovie:(NSString *)urlStr{ 
NSURL *fileURL = [NSURL URLWithString:urlStr]; 
player = [[MPMoviePlayerController alloc] initWithContentURL:fileURL]; 
player.scalingMode = MPMovieScalingModeAspectFit; 
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willEnterFullscreen:) name:MPMoviePlayerWillEnterFullscreenNotification object:nil]; 
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willExitFullscreen:) name:MPMoviePlayerWillExitFullscreenNotification object:nil];  
[[appDelegate loginViewController].view removeFromSuperview]; 
[[appDelegate tabBarController].view removeFromSuperview]; 
[[appDelegate navController].view addSubview:player.view]; 
player.fullscreen = YES; 
[player play]; 

}

- (void)willExitFullscreen:(NSNotification*)notification { 
NSLog(@"willExitFullscreen..."); 
[[appDelegate window] addSubview:[appDelegate navController].view]; 
[[appDelegate window] addSubview:[appDelegate loginViewController].view]; 
[[appDelegate window] addSubview:[appDelegate tabBarController].view]; 
[player.view removeFromSuperview]; 

}

回答

0

呈現播放器上使用:

[self presentMoviePlayerViewControllerAnimated:player]; 
//Self should be a View Controller. 

,而不是使用addSubview

此外,你應該確保設置movieSourceTypeplayer(您可以通過訪問player.moviePlayer),並作爲推薦集合使用player.view.backgroundColor = [UIColor blackColor];避免閃爍的白色背景上播放的背景。

+0

這個答案顯然是錯誤的。有關MPMoviePlayerController而不是MPMoviePlayerViewController的問題。 –

+0

似乎用戶在我的回覆之前編輯了問題。 – Raspu