2012-03-20 13 views
3

こんにちは、私は私だけiPhoneアプリ:MPMoviePlayer:PlayVideoは、風景モードでのみ

どのように私はそれを達成することができランドスケープモードでビデオを再生するためにmpmovieplayerを作りたいonly.Butポートレートモードで実行する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の設定を行う必要はありません。 –

答えて

1

あなたは風景のセットアップのIT独自のビューコントローラでムービーを提示することができます。

// 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でした。 isLandscapeOK == YESの場合、このMovieVCはYESに設定し、他のタブVCはポートレートまたはランドスケープに応答します。

+0

あなたの最終的な注釈を参照すると、そのviewControllerをモーダルで表示することもできます。そのため、説明されている方向の副作用(タブバー、ナビゲーションバー)は一切ありません。 – Till

関連する問題