13

多数のビデオを次々と再生するビデオ アプリケーションに取り組んでいます。ビデオは の配列に格納されAVPlayerItemます。AVQueuePlayerそれらで初期化さAVPlayerItemsれ、その配列からビデオを自動的に再生します。

問題は、次のビデオを再生するように変更するときに、ほんの一瞬スタックするか、あるビデオから別のビデオに移行するときにぎくしゃくすることです。ビデオが変更されている間、フェードインやフェードアウトなどのアニメーションを使用して、このトランジションを改善したいと考えています。

私のコードAVQueuePlayer

AVQueuePlayer *mediaPlayer = [[AVQueuePlayer alloc] initWithItems:arrPlayerItems];
playerLayer=[AVPlayerLayer playerLayerWithPlayer:mediaPlayer];
playerLayer.frame=self.bounds;
playerLayer.videoGravity = AVLayerVideoGravityResizeAspect;
playerLayer.needsDisplayOnBoundsChange = NO;
[self.layer addSublayer:playerLayer];
self.layer.needsDisplayOnBoundsChange = YES;

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(itemPlayEnded:)
                                             name:AVPlayerItemDidPlayToEndTimeNotification
                                           object:[mediaPlayer currentItem]];

トランジション時に新しいレイヤーを作成し、その不透明度を下げて新しいレイヤーの不透明度を上げて古いレイヤーをアニメーション化しようとしましたが(目的のフェードインフェードアウト効果を作成するため)、期待どおりに機能しません。

カスタム遷移のコード:

-(void)TransitionInVideos {
    if (roundf(CMTimeGetSeconds(mediaPlayer.currentTime))==roundf(CMTimeGetSeconds(mediaPlayer.currentItem.duration))) {
        [self.layer addSublayer:playerLayerTmp];

        //Animation for the transition between videos
        [self performSelector:@selector(FadeIn) withObject:nil afterDelay:0.3];
        [self performSelector:@selector(FadeOut) withObject:nil afterDelay:0.3];
    }
}

-(void)FadeIn {
    CABasicAnimation* fadeAnim = [CABasicAnimation animationWithKeyPath:@"opacity"];
    fadeAnim.fromValue = [NSNumber numberWithFloat:1.0];
    fadeAnim.toValue = [NSNumber numberWithFloat:0.0];
    fadeAnim.duration = 2.0;
    [playerLayer addAnimation:fadeAnim forKey:@"opacity"];
    [self performSelector:@selector(HideLayer) withObject:nil afterDelay:2.0];
}

-(void)FadeOut {
    CABasicAnimation* fadeAnim = [CABasicAnimation animationWithKeyPath:@"opacity"];
    fadeAnim.fromValue = [NSNumber numberWithFloat:0.0];
    fadeAnim.toValue = [NSNumber numberWithFloat:1.0];
    fadeAnim.duration = 1.0;
    [playerLayerTmp addAnimation:fadeAnim forKey:@"opacity"];
    [self performSelector:@selector(ShowLayer) withObject:nil afterDelay:1.0];
}

-(void)HideLayer {
    playerLayer.opacity=0.0;
}

-(void)ShowLayer {
    playerLayerTmp.opacity=1.0;
}

のビデオにトランジションを適用するにはどうすればよいAVQueuePlayerですか?

4

3 に答える 3

2

アプリの 1 つでまったく同じ問題が発生しました。残念ながら、標準のプレーヤーを削除して、この例のロジックを使用する必要がありました。

https://developer.apple.com/library/ios/samplecode/StitchedStreamPlayer/Listings/Classes_MyStreamingMovieViewController_m.html#//apple_ref/doc/uid/DTS40010092-Classes_MyStreamingMovieViewController_m-DontLinkElementID_8

それが役立つことを願っています。

于 2013-11-14T19:05:37.157 に答える
1

連続して再生する 2 つの別個の AVPlayer オブジェクトを使用することで、目的の効果を得ることができました。プレイヤーはさまざまなビューを使用してプレイしています。

アイデアは、最初のビデオが終了する前に、2 番目のビデオ プレーヤーのビューにフェード インすることです。

デモ プロジェクトは次の場所にあります: IHLoopingVideoPlayerView

同じビデオを何度もループしますが、同じアイデアをいくつのビデオにも適用できます。

于 2016-08-11T22:19:51.683 に答える