playbackLikelyToKeepUp 和 AVPlayerItemStatusReadyToPlay 有什么区别?

What's the difference between playbackLikelyToKeepUp and AVPlayerItemStatusReadyToPlay?

我正在尝试了解如何正确检测播放器项目何时可以再次播放。

查看下面的观察者逻辑:

if (object == playerItem && [keyPath isEqualToString:@"playbackBufferEmpty"])
{
    if (playerItem.playbackBufferEmpty) 
    {
        // show loading indicator
    }
}

if (object == playerItem && [keyPath isEqualToString:@"playbackLikelyToKeepUp"])
{
    if (playerItem.playbackLikelyToKeepUp)
    {
        // hide loading indicator

        if (playerItem.status == AVPlayerItemStatusReadyToPlay) {
            // start playing
        }
        else if (playerItem.status == AVPlayerStatusFailed) {
            // handle failed
        }
        else if (playerItem.status == AVPlayerStatusUnknown) {
            // handle unknown
        }
    }
}

playbackLikelyToKeepUp 下面检查 AVPlayerItemStatusReadyToPlay 是不是太过分了?

我是否应该只听 status 播放器项目的变化而不是费心 playbackLikelyToKeepUp

这两个属性告诉我们关于 AVPlayerItem 状态的两条不同信息。 AVPlayerItemStatusReadyToPlay 是一个常量,只有在 AVPlayer 有足够的时间缓冲足够的项目数据以便它能够开始播放项目时,才会指示 readyToPlay。但仅此而已。仅仅因为一个项目已准备好播放,并不意味着它不会在前几秒后停止。

playBackLikelyToKeepUp returns a bool indicating that playback of the item is "likely" to keep up throughout the duration of the item. This property does NOT only pertain to the beginning of the item, like AVPlayerItemStatusReadyToPlay. It does not "care" if the item is ready for playback, all it "cares" about is wether or not it "thinks" that playback of the item will keep up without stalling. This is a PREDICTION of playability that takes into account various factors which you can read about here -> https://developer.apple.com/documentation/avfoundation/avplayeritemstatus

所以关于您的问题,在您已经检查了 playbackLikelyToKeepUp 之后检查 AVPlayerItemStatusReadyToPlay 的值是否有点过分了...这取决于您。我个人会检查两者。我想首先确保该项目已准备好播放,这意味着 AVPlayer 已经缓冲了足够的数据以便开始播放。然后我想确保 playbackLikeyToKeepUp == true 这样我就可以在一定程度上确定用户的媒体体验不会被打断。但是,如果您只关心知道项目何时准备好再次开始播放,那么您只需要检查 status