Hello! I am trying to determine the best approach with AVPlayer
for implementing auto-play, that is, playback that automatically starts without user initiation. Ideally this would work for both local and streaming audio.
My current approach is using KVO and the status
on an AVPlayerItem
equal to readyToPlay
to do this, but I was wondering if there was a better property or state to use, or, alternatively, whether this use case may already be handled when automaticallyWaitsToMinimizeStalling
is true
, so that I could simply write:
player.replaceCurrentItem(with: AVPlayerItem(url: streamingUrl))
player.rate = 1
or
let playerItem = AVPlayerItem(url: streamingUrl)
player = AVPlayer(playerItem: playerItem)
player.rate = 1
and expect the item to be auto-played when ready.
In the context of user-initiated playback, I've typically seen code that makes a button's enabled state contingent on player.currentItem.duration
, e.g. in AVFoundationSimplePlayer-iOS
. On the other hand, AVAutoWait
, which utilizes automaticallyWaitsToMinimizeStalling
, does not seem to do this.
As a side note, I am not using an AVQueuePlayer
.