2014-01-21 36 views
6

在我的項目中,我使用嵌入式視圖,其中包含MPMoviePlayerController。MPMoviePlayerController在全屏模式下停止工作//縱向定向// iOS 7

此電影播放器​​在點擊全屏切換後停止工作 - 它在全屏模式下再播放1秒,然後停止並返回到嵌入模式。

它只發生在縱向模式下,僅適用於iOS 7 - 如果我在橫向模式下切換全屏模式,然後旋轉設備,它會正常工作。

我找到了原因 - 不知何故導航欄參與。我在項目中使用ECSlidingViewController並設置導航欄半透明「NO」初始化過程中:

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:myViewController]; 

navController.navigationBar.translucent = NO; 

self.topViewController = navController; 

如果我設置了navController.navigationBar.translucent = YES;電影播放器​​工作正常。但我必須有半透明=否。

所以我試圖玩電影播放器​​事件MPMoviePlayerWillEnterFullscreenNotification和MPMoviePlayerWillExitFullscreenNotification。 有趣的是,如果我在進入全屏模式之前讓navBar半透明或隱藏它,視頻播放時間會更長一些(大約3-4秒),但行爲是相同的。

[[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(moviePlayerWillEnterFullScreen:) 
               name:MPMoviePlayerWillEnterFullscreenNotification 
               object:nil]; 


-(void)moviePlayerWillEnterFullScreen:(id)sender{ 

    [self.navigationController setNavigationBarHidden:YES animated:NO]; 

OR 
    self.navigationController.navigationBar.translucent = YES; 
} 

任何想法我可以用這個做的是大加讚賞。

UPD。 這個bug在iOS 7.0.4中沒有了

+0

聽起來好像有某種類別的(僞重寫)掛羊頭賣狗肉導航欄繼續。如果是這種情況,確保每次使用播放器時禁用它,因爲它的接口實際上依賴於UINavigationBar作爲上部。如果不禁用,那個類別上的類別以及swizzles在後面都會留下混亂。 – Till

+0

謝謝@Till我檢查了項目 - 沒有類別或其他navBar定製。 –

+0

那還包括'UINavigationBar'的'drawRect:'代碼,是否正確? – Till

回答

3

IMP:如果你使用的是ARC,我相信你需要保留外面的moviePlayer。我自己把它分配給一個新的屬性。

我嘗試了以下兩種方式併爲我工作。

如果您將自我視圖用作整個屏幕。

NSURL *url = [[NSBundle mainBundle] URLForResource:@"Robot" withExtension:@"m4v"]; 
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url]; 
moviePlayer.controlStyle = MPMovieControlStyleFullscreen; 
moviePlayer.view.transform = CGAffineTransformConcat(moviePlayer.view.transform,   CGAffineTransformMakeRotation(M_PI_2)); 
[moviePlayer.view setFrame: self.view.bounds]; 
[self.view addSubview: moviePlayer.view]; 
[moviePlayer play]; 

,並且不使用自我查看您可以用整個全屏工作(它不會調用全屏屬性)的

NSURL *url = [[NSBundle mainBundle] URLForResource:@"Robot" withExtension:@"m4v"]; 
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url]; 
moviePlayer.controlStyle = MPMovieControlStyleFullscreen; 
moviePlayer.view.transform = CGAffineTransformConcat(moviePlayer.view.transform, CGAffineTransformMakeRotation(M_PI_2)); 
UIWindow *backgroundWindow = [[UIApplication sharedApplication] keyWindow]; 
[moviePlayer.view setFrame:backgroundWindow.frame]; 
[backgroundWindow addSubview:moviePlayer.view]; 
[moviePlayer play]; 
+0

謝謝。該錯誤已在iOS 7.0.4 –

+0

@ Dmitry Khryukin消失如果它有幫助。你應該接受答案。 – python

相關問題