3

I have an AVPlayerLooper which uses an AVQueuePlayer. It's really easy to loop the video, but I wanted to fade in the video during the first second, and fade out during the last second. I've been able to make it fade in and out by using an AVPlayerLayer and a CABasicAnimation which animates the opacity appropriately, but I can't make it seamless and 100% reliable. I've tried using NotificationCenter for the AVPlayerItemDidPlayToEndTime and AVPlayerItemTimeJumped. I've also tried using KVO with the key isReadyForDisplay. When I tried to addPeriodicTimeObserver, I can't get it accurate enough to correctly time the fades. I've even tried to addBoundaryTimeObserver, but that wasn't consistent enough either.

Does anybody have any suggestions as to how to implement a crossfade into an AVPlayerLooper/AVQueuePlayer?

se_puede_dev
  • 585
  • 7
  • 16

1 Answers1

0

AVPlayerLooper has always struck me as a strange class - wouldn't looping have been more orthogonal and useful as a wrapped AVAssetTrack or even an AVPlayerItem? e.g.

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

Anyway, you could create your initial fade in as a AVMutableComposition and queue it up, then queue up the AVPlayerLooper looping version that you've already done.

As for fade out, you can queue up a fade-out, which will play once you stop the looping with looper.disableLooping(). (actually, maybe this answers my question, having disableLooping on an AVAssetTrack or AVPlayerItem would be weird).

Rhythmic Fistman
  • 34,352
  • 5
  • 87
  • 159