2011-01-19 17 views
3

アプリはポートレートモードのみですが、ユーザーがビデオを再生すると、フルスクリーンのランドスケープモードで再生したい(ビデオプレーヤーが似ていないモード)。私は次のように演奏しています:iphone - 風景モードでビデオを再生するMPMoviePlayerController

[self.view addSubview:myMoviePlayer.view]; 
[self.myMoviePlayer setFullscreen:YES animated:YES]; 
[self.myMoviePlayer play]; 

これを行うにはどうすればよいでしょうか?

答えて

7

この記事を読む:

http://iosdevelopertips.com/video/getting-mpmovieplayercontroller-to-cooperate-with-ios4-3-2-ipad-and-earlier-versions-of-iphone-sdk.html

主なアイデアがある:フルスクリーン再生のために

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO]; 

[[self view] setBounds:CGRectMake(0, 0, 480, 320)]; 
[[self view] setCenter:CGPointMake(160, 240)]; 
[[self view] setTransform:CGAffineTransformMakeRotation(M_PI/2)]; 
0

それは「shouldAutorotateToInterfaceOrientationを使用するランドスケープ形式で起動して再生させるために、その後MPMoviePlayerViewControllerを使用し、 "メソッドをMPMoviePlayerViewControllerクラスに追加します。

それは次のようになります。

[yourInstanceOfMPMoviePlayerViewController shouldAutorotateToInterfaceOrientation: UIInterfaceOrientationLandscapeRight]; 
+0

これはIOS 6では廃止されており、実際にはプレーヤーは回転しません。 –

+0

これは私のために働いていない - 私は映画を提示するビューコントローラを持って、その風景モードでは、完全には、映画はまだ肖像画で起動...アイデア? –

0

私は同じような状況があったが、私はiOSの6とからNavControllerベースのプロジェクトを使用しています。興味深いのは、私が回転させたくないMPMoviePlayerControllerをホストしているViewControllerですが、その中のビデオを回転させたいと思っていました。

ViewController with rotated MPMoviePlayerController
デバイスの向きに基づいて、必要に応じて私は手動でMPMoviePlayerControllerを回転させます。 _videoViewは、ViewControllerのMPMoviePlayerControllerプロパティです。この例では、このビデオをYouTubeにアップロードする予定のため、希望の幅と高さを16×9のアスペクト比にハードコードしました。

- (void)updateVideoRotationForCurrentRotationWithAnimation:(bool)animation 
{ 
    CGSize containerSize = _videoView.frame.size; // Container NOT rotated! 
    float videoWidth  = 384;      // Keep 16x9 aspect ratio 
    float videoHeight = 216; 

    if(animation) 
    { 
     [UIView beginAnimations:@"swing" context:nil]; 
     [UIView setAnimationDuration:0.25]; 
    } 

    switch(self.interfaceOrientation) 
    { 
     case UIInterfaceOrientationPortrait: 
     case UIInterfaceOrientationPortraitUpsideDown: 
      m_videoPlayer.view.transform = CGAffineTransformMakeRotation(radians(90)); 

      // This video player is rotated so flip width and height, but the container view 
      // isn't rotated! 
      [m_videoPlayer.view setFrame:CGRectMake((containerSize.width-videoHeight)/2, 
                (containerSize.height-videoWidth)/2, 
                videoHeight, 
                videoWidth)]; 
      break; 

     case UIInterfaceOrientationLandscapeLeft: 
     case UIInterfaceOrientationLandscapeRight: 
      m_videoPlayer.view.transform = CGAffineTransformMakeRotation(radians(0)); 

      // This video player isn't rotated 
      [m_videoPlayer.view setFrame:CGRectMake((containerSize.width-videoWidth)/2, 
                (containerSize.height-videoHeight)/2, 
                videoWidth, 
                videoHeight)]; 
      break; 
    } 

    if(animation) 
     [UIView commitAnimations]; 

} 


- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation 
{ 
    [self updateVideoRotationForCurrentRotationWithAnimation:YES]; 
} 

私もそれが正しい初期配向しているので、表示されたビュー後updateVideoRotationForCurrentRotationWithAnimationを呼び出します。

1

私のアプリは、メインナビゲーション画面といくつかの詳細画面を表示するルートビューコントローラとしてUINavigationControllerを使って、とてもシンプルです。メイン画面はレイアウトの制約により回転をサポートしていません。また、一貫性のために、詳細画面(単純にナビコントローラのスタックにプッシュされます)はどちらも表示されません。ただし、一部の詳細画面にはビデオへのリンクが含まれており、ビデオはポートレートモードで表示する必要があります。アプリはMPMoviePlayerControllerを使用してモーダルプレイヤーを表示します。

私はちょうど同様の問題を抱えていましたが、MPMoviePlayerControllerのビューにアファイン変換を適用する上記の解決策を試しましたが、ステータスバーがポートレートモードで表示され続け、モーダルムービープレーヤビュー上記の回転に従って見た場合、左側にある)。私は無駄に物事のカップルを試してみました:

  • は、ステータスバーを非表示にします。これは機能しませんでした。なぜなら、プレーヤーは自分の世界に存在していて、先に進んで、とにかくステータスバーを提示するからです。私はこれをなくす方法を見つけることができませんでした。

  • ステータスバーの向きを明示的に設定します。私はなぜこれがうまくいかなかったのか正確にはわかりませんが、私はinfo.plistで肖像画のみがサポートされていて、変更を断念していたと指摘していたからです。

上記のNet-netは機能しませんでした。ちょうど同様に、b/c AppleはdevsにMPMoviePlayerControllerを不透明なものとして扱い、(特にtransformメソッドで)私はこれを違反していると警告します。最後に

、私は私のために働いた簡単な解決策が見つかりました:Info.plistのでは

  1. を、私は(逆さまを除いて、そのiPhoneの標準イディオム)すべての方向がサポートされたことを示しました。

  2. サブクラスUINavigationController

    、およびのみポートレートがサポートされているように、適切なshouldAutorotateメソッドをオーバーライド(同時にIOSの< 6とiOS6でこれを行う方法については、とりわけ、this solutionを参照されたいです)。

。これは働いていた:私はオートローテーションは、アプリによってサポートされていることが示されたと思いますが

  1. 、私は、レンダリングてるすべてのビューが含まれているUINavigationControllerサブクラスでそれをカット。 ..

  2. MPMoviePlayerControllerは、NavigationControllerの上にモーダルで表示され、独自の世界に居住しています。したがって、info.plistの内容には注意を払い、すべてを単独で回転させてください。

モーダルプレーヤーを提示する方法については、例の束がありますが、簡単に参照するために、ここに私のコードです:私はのMoviePlayerのための唯一のランドスケープモードで動作するように次のコードを使用

- (void)presentModalMediaPlayerForURL:(NSURL *)inURL 
{ 
    NSLog(@"Will play URL [%@]", [inURL description]); 
    MPMoviePlayerViewController *player = [[MPMoviePlayerViewController alloc] initWithContentURL:inURL]; 
    [player.view setBounds:self.view.bounds]; 

    [player.moviePlayer prepareToPlay]; 
    [player.moviePlayer setFullscreen:YES animated:YES]; 
    [player.moviePlayer setShouldAutoplay:YES]; 
    [player.moviePlayer setMovieSourceType:MPMovieSourceTypeFile]; 
    [self presentModalViewController:player animated:YES]; 

    [player release]; 
} 
0

NSURL *movieURL = [NSURL URLWithString:@"http://techslides.com/demos/sample-videos/small.mp4"]; // sample url 
MPMoviePlayerViewController *movieController = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL]; 

// Logic for play movie in landscape 
CGAffineTransform landscapeTransform; 
landscapeTransform = CGAffineTransformMakeRotation(90*M_PI/180.0f); 
landscapeTransform = CGAffineTransformTranslate(landscapeTransform, 80, 80); 
[movieController.moviePlayer.view setTransform: landscapeTransform]; 

[self presentMoviePlayerViewControllerAnimated:movieController]; 
[movieController.moviePlayer prepareToPlay]; 
[movieController.moviePlayer play]; 
関連する問題