2012-04-21 12 views
1

私はiPadアプリで2つのムービーの間に滑らかなクロスフェードを作りたいと思っています。ボタンをタップすると、ビジュアルでランダムに&が再生されているムービーが次のムービーにフェードします。MPMoviePlayerControllerを使って2つのムービーを切り替える

2つの映画は(ドキュメントから)同時に再生できないので、簡単なクロスフェードはできません。これを回避するには、新しいムービーの最初のフレームの静止画を使用します(フェードインされます)。私は映画の交換を扱うために2人のプレーヤーを使用しました。

元のムービーが一時停止しています。その後、画像に切り替わります。今度は2番目のムービー(アルファ= 0.0)&を追加してアルファ= 1となるようにトランジションします。新しいムービーを再生します。これは、新しいムービーが画像上に移るにつれて目立って暗くなることを除いてすべて正常に機能します。

私はまだ静止画なしでそれをテストしました&この変化の間に黒ずみが発生していないようです。

スイッチのマイコードは以下のとおりです(if文の前半部分)。それはかなり奇妙に見える、それを見て、それは私が必要なものに私をもたらした方法です。

多分、このタスクについてもっと良い方法がありますか?

- (void) switchMovie; 
{ 

NSURL *movieImageUrl = [movieImageUrlArray objectAtIndex:index]; 
NSData *data = [NSData dataWithContentsOfURL:movieImageUrl]; 
UIImage *movieImage = [[UIImage alloc] initWithData:data]; 
UIImageView *image = [[UIImageView alloc] initWithImage:movieImage]; 

image.alpha = 0.0f; 
[self addSubview:image]; 

if (moviePlayer1Playing) { 

moviePlayer1Playing = NO; 
moviePlayer2Playing = NO; 

[moviePlayer1 pause]; //pausing later in the method caused a crash, stopping causes a crash. 

[UIView animateWithDuration:1.0 
         delay:0.0 
        options:UIViewAnimationCurveEaseIn 
       animations:^{ 

        image.alpha = 1.0f;    //fade in still of first frame of new movie 

       } completion:^(BOOL finished) { 

        [moviePlayer1 release]; //release original movie. 

        moviePlayer2 = [[MPMoviePlayerController alloc] initWithContentURL:[movieUrlArray objectAtIndex:index]]; 

        moviePlayer2.shouldAutoplay = NO; 
        [moviePlayer2 prepareToPlay]; 
        [moviePlayer2 setControlStyle:MPMovieControlStyleNone]; 
        moviePlayer2.scalingMode = MPMovieScalingModeAspectFill; 
        [moviePlayer2.view setFrame:CGRectMake(0, 0, 1024 , 768)]; 
        moviePlayer2.view.backgroundColor = [UIColor clearColor]; 
        moviePlayer2.view.alpha = 0.0; 
        [self addSubview:moviePlayer2.view]; 

        [UIView animateWithDuration: 3.0 
              delay: 0.0 
             options: UIViewAnimationCurveLinear 
             animations:^(void){ 

             moviePlayer2.view.alpha = 1.0f; 
             //During this transition the view goes dark half-way through, before lightening again. 

             } completion:^ (BOOL finished) { 

              [moviePlayer2 play]; 
              moviePlayer2Playing = YES; 
              moviePlayer1Playing = NO; 


             }]; 

       }]; 


} 

答えて

1

ご覧黒:)事前に感謝は、ムービープレーヤーの背景なので、代わりに、まだのためにUIImageViewを使用して、あなたはまだ希望ムービープレイヤーの背景を設定する必要があります。

UIImageView *stillImageView = [UIImageView alloc]initWithImage:stillImage]; 
stillImageView.frame = self.moviePlayer.backgroundView.frame; 

[self.moviePlayer.backgroundView addSubview:stillImageView]; 
[stillImageView release]; 
+0

これは問題を解決するのには最適な方法ですが、まだ映画の背景として静止画像を追加することはできません。ライン:[self.movi​​ePlayer.backgroundView addSubview:stillImageView]; が実装されていません - 私が見ることができるのは青色の背景色です(イラスト用に設定しています)、背景色は背景色に加えられません。大規模なムービーファイルの処理がハードウェアコーデックで処理される可能性はありますか? – Octave1

+0

それは奇妙です。私がここに投稿したコードは、これまでにやったプロジェクトから取ったものです。あなたの問題を再現できるかどうかを確認するために、いくつかのバリエーションを試してみましょう。 –

関連する問題