我有一个问题: 我的应用程序中的AVPlayer开始播放来自URL的音频太长时间。这需要5到15秒。
更多,它给出了错误的(我猜是)等待原因:“ AVPlayerWaitingWithNoItemToPlayReason”。 这是我的开始播放方法:
private func setNewPlayerItem(with url: URL) {
player.automaticallyWaitsToMinimizeStalling = false
player.replaceCurrentItem(with: .init(url: url))
player.play()
}
这是我的调试。看时间。
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)
如您所见, .currentItem 存在,因此等待原因“ AVPlayerWaitingWithNoItemToPlayReason”是错误的。但是为什么 .timeControlStatus 在“播放” 之后更改为“ waitingToPlayAtSpecifiedRate” ?
此解决方案也不适用于我:
player.playImmediately(atRate: 1.0)
它发生在每个轨道上,因此问题不在轨道上。
请帮助!