【问题标题】:How can I add a smooth fade in/out transition to AVPlayerLooper?如何向 AVPlayerLooper 添加平滑的淡入/淡出过渡?
【发布时间】:2017-10-04 09:46:27
【问题描述】:

我有一个AVPlayerLooper,它使用AVQueuePlayer。循环播放视频真的很容易,但我想在第一秒淡入视频,在最后一秒淡出。我已经能够通过使用AVPlayerLayerCABasicAnimation 来使其淡入和淡出,它们可以适当地为不透明度设置动画,但我无法使其无缝且100% 可靠。我尝试将NotificationCenter 用于AVPlayerItemDidPlayToEndTimeAVPlayerItemTimeJumped。我也尝试使用带有密钥isReadyForDisplay 的KVO。当我尝试addPeriodicTimeObserver 时,我无法获得足够准确的时间来正确地确定淡入淡出的时间。我什至尝试过addBoundaryTimeObserver,但这也不够一致。

有人对如何在 AVPlayerLooper/AVQueuePlayer 中实现交叉淡入淡出有任何建议吗?

【问题讨论】:

    标签: ios swift avfoundation avplayer avplayerlayer


    【解决方案1】:

    AVPlayerLooper 总是让我印象深刻,因为它是一个奇怪的类——循环不会像包装的 AVAssetTrack 甚至是 AVPlayerItem 那样更加正交和有用吗?例如

    loop(AVAssetTrack) -> AVAssetTrack
    loop(AVPlayerItem) -> AVPlayerItem
    

    无论如何,您可以将初始淡入创建为 AVMutableComposition 并将其排队,然后将您已经完成的 AVPlayerLooper 循环版本排队。

    至于淡出,你可以排队一个淡出,一旦你用looper.disableLooping()停止循环就会播放。 (实际上,也许这回答了我的问题,在 AVAssetTrackAVPlayerItem 上使用 disableLooping 会很奇怪)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-21
      • 2012-02-04
      相关资源
      最近更新 更多