2011-04-16 86 views
2

我的代碼播放視頻文件時出現問題。每當我以全屏模式播放文件時,播放不會佔用我的全部屏幕。下面是相關代碼:MPMoviePlayerController全屏模式問題

 NSURL *url = [NSURL fileURLWithPath:@"Somefile.mov"]; 
    moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url]; 
    [moviePlayer setControlStyle:MPMovieControlStyleFullscreen]; 
    [moviePlayer setFullscreen:YES]; 
    moviePlayer.view.frame = self.switchView.frame; 
    [self.switchView addSubview:moviePlayer.view]; 

    [[NSNotificationCenter defaultCenter] 
    addObserver:self 
    selector:@selector(movieFinishedCallback:)             
    name:MPMoviePlayerPlaybackDidFinishNotification 
    object:moviePlayer]; 

    [[NSNotificationCenter defaultCenter] 
    addObserver:self 
    selector:@selector(playbackStateDidChange:)             
    name:MPMoviePlayerPlaybackStateDidChangeNotification 
    object:moviePlayer]; 

    [moviePlayer prepareToPlay]; 
    [moviePlayer play]; 

這裏是輸出我得到:

enter image description here

+0

嘗試這一個,而不是你正在設置的框架moviePlayer.view.frame = self.switchView.bounds; – Ravin 2011-04-17 09:56:04

+0

現在看來下方的酒吧處於正確的位置,但頂部酒吧仍然較低。 http://img849.imageshack.us/i/defaultj.png/ – Diurpaneus 2011-04-17 11:23:48

回答

7

選項A:使用MPMovieViewController,而不是使用presentMoviePlayerViewControllerAnimated:顯示它模態。

選項B:確保您的switchView(用於添加moviePlayer的視圖)實際佔用整個屏幕。

選項C:重新調整moviePlayer的負垂直偏移視圖的框架,直到它符合 - 如:moviePlayer.view.frame = CGRectMake(0.0f, -20.0f, 320.0f, 480.0f);

注:的MPMoviePlayerController 總是顯示器使用控制風格MPMovieControlStyleFullscreen時,無論怎樣一個狀態欄其餘的應用程序處理狀態欄。

+0

我做了選項C,它解決了我的問題。另外在viewDidAppear中,我把moviePlayer.view.frame = CGRectMake(0.0f,-20.0f,320.0f,480.0f);因爲否則電影屏幕跳躍!但對於addSubView部分,我將它放在0.0f上。 – rockstarberlin 2013-11-28 15:47:45

1

更改您的播放器從下面的方法ControlStyle屬性: - (無效)applyUserSettingsToMoviePlayer

player.controlStyle = MPMovieControlStyleFullScreen導致上述問題,將其更改爲MPMovieControlStyleEmbedded,看看是否可行。