I have a problem: AVPlayer in my app starts playing audio from URL too long. It takes 5-15 seconds.
More, it gives wrong (as I guess) waiting reason: "AVPlayerWaitingWithNoItemToPlayReason". Here is my start playing method:
private func setNewPlayerItem(with url: URL) {
player.automaticallyWaitsToMinimizeStalling = false
player.replaceCurrentItem(with: .init(url: url))
player.play()
}
And here is my debug. Look at the time.
2019-05-31 16:40:06 +0000 player timeControlStatus 0 (paused)
2019-05-31 16:40:06 +0000 player status 0 (unknown)
2019-05-31 16:40:06 +0000 player currentItem nil
2019-05-31 16:40:15 +0000 player currentItem Optional(<AVPlayerItem: 0x600003a34fa0, asset = <AVURLAsset: 0x600003889a40, URL = *valid URL*>>)
2019-05-31 16:40:15 +0000 player currentItem status 0 (unknown)
2019-05-31 16:40:15 +0000 player timeControlStatus 2 (playing)
2019-05-31 16:40:22 +0000 player status 1 (readyToPlay)
2019-05-31 16:40:22 +0000 player timeControlStatus 1 (waitingToPlayAtSpecifiedRate)
2019-05-31 16:40:22 +0000 player timeControlStatus 2 (playing)
2019-05-31 16:40:23 +0000 player currentItem status 1 (readyToPlay)
As you can see, .currentItem exists, so waiting reason "AVPlayerWaitingWithNoItemToPlayReason" is wrong. But why .timeControlStatus changes to "waitingToPlayAtSpecifiedRate" after "playing"?
This solution also doesn't work for me:
player.playImmediately(atRate: 1.0)
It happens with each track, so the issue is not in track.
Please help!