How to add a smooth I / O transition to AVPlayerLooper?
I have AVPlayerLooper
one that uses AVQueuePlayer
. It's very easy to loop the video, but I wanted to fade out in the video for the first second and fade out in the last second. I was able to get it to fade out and use with AVPlayerLayer
and CABasicAnimation
, which animate the opacity appropriately, but I cannot make it seamless and 100% reliable. I tried using NotificationCenter
for AVPlayerItemDidPlayToEndTime
and AVPlayerItemTimeJumped
. I also tried to use KVO with a key isReadyForDisplay
. When I tried addPeriodicTimeObserver
, I can't get it accurate enough to fade out correctly. I even tried addBoundaryTimeObserver
, but that was consistent too.
Are there any suggestions on how to implement crossfade in AVPlayerLooper / AVQueuePlayer?
source to share
AVPlayerLooper
always struck me as a weird class - wouldn't loops be more orthogonal and useful as wrapped AVAssetTrack
or even AVPlayerItem
? eg.
loop(AVAssetTrack) -> AVAssetTrack
loop(AVPlayerItem) -> AVPlayerItem
Anyway, you can create an initial fade in the view AVMutableComposition
and enqueue it, and then enqueue the loop version AVPlayerLooper
you already did.
As for fading out, you can queue a fade out to play after you stop the loop with looper.disableLooping()
. (actually, maybe this answers my question: disableLooping
on AVAssetTrack
or AVPlayerItem
would be strange).
source to share