2012-03-20 70 views
3

您好我有這在肖像模式而已。不過我想使mpmovieplayer在風景模式下iPhone應用程序:MPMoviePlayer:調用playVideo在風景模式下

播放視頻我怎樣才能做到這一點運行的iPhone應用程序?

這裏是代碼。

NSString *path = [[NSBundle mainBundle] pathForResource:lblVideoName.text ofType:@"mp4" inDirectory:nil]; 
    NSURL *url = [[NSURL alloc] initFileURLWithPath:path]; 
    NSLog(@"URL== %@",url); 
    moviePlayer = [[MPMoviePlayerController alloc] 
        initWithContentURL:url]; 


    moviePlayer.controlStyle = MPMovieControlStyleDefault; 
    moviePlayer.shouldAutoplay = YES; 
    [self.view addSubview:moviePlayer.view]; 
    [moviePlayer setFullscreen:YES animated:YES]; 

請幫助和建議。

感謝

+0

您不需要在MPMovieController中執行任何設置,而是管理視圖方向。 – 2012-03-21 04:51:39

回答

1

你能呈現電影在它自己的看法控制器的設置景觀。

// in the VC where the user indicates he wants to see a movie... 
- (void)startTheMovie { 
    // run a storyboard segue with a modal transition, or ... 
    MyMovieVC *movieVC = [[MyMovieVC alloc] initWithNibName:@"MyMovieVC" bundle:nil]; 
    [self presentModalViewController:movieVC animated:YES]; 
} 

// in MyMovieVC 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || 
     (interfaceOrientation == UIInterfaceOrientationLandscapeRight); 
} 

// and the code that you wrote on view will appear 

您可以在此界面中包含解除按鈕,或者,YouTube的方式是讓它自行解散。你可以做到這一點通過訂閱成品通知:

[[NSNotificationCenter defaultCenter] addObserver:self 
selector:@selector(moviePlayerFinished:) 
name:MPMoviePlayerPlaybackDidFinishNotification object:nil]; 

然後,對成品消息

- (void)moviePlayerFinished:(NSNotification*)notification { 
    [self dismissModalViewControllerAnimated:YES]; 
} 

注意,如果你在一個標籤式界面這樣做,所有的標籤 - 即使是那些不可見的 - 需要同意讓界面變成風景。這有些道理,但過去讓我感到心痛。我沒有一個漂亮的解決方案。我的方法是在我的AppDelegate上公開訪問BOOL isLandscapeOK。此MovieVC將其設置爲YES,如果isLandscapeOK == YES,則其他選項卡VC將回答縱向或橫向。

+0

參考你最後的注意事項:你也可以簡單地顯示該viewController模態,因此沒有任何描述的方向sideeffects(標籤欄,導航欄)。 – Till 2012-03-20 15:45:29

相關問題