Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between playbackLikelyToKeepUp and AVPlayerItemStatusReadyToPlay?

I'm trying to understand how to properly detect when a player item can play again.

See below observer logic:

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
        }
    }
}

Is checking for AVPlayerItemStatusReadyToPlay underneath playbackLikelyToKeepUp overkill?

Or

Should I only listen to status change on the player item instead of bothering with playbackLikelyToKeepUp?

like image 505
Mark13426 Avatar asked Feb 05 '16 18:02

Mark13426


1 Answers

The two properties inform us of two different pieces of information in regards to the status of an AVPlayerItem. AVPlayerItemStatusReadyToPlay is a constant that will indicate readyToPlay ONLY once an AVPlayer has been given sufficient time to buffer enough of the item's data such that it is able to BEGIN playback of the item. But that is it. Just because an item is ready to play, doesn't mean that it won't stall after the first few seconds.

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

So in regards to your question, is it overkill to check the value of AVPlayerItemStatusReadyToPlay after you've already checked playbackLikelyToKeepUp... well it is up to you. I personally would check both. I would want to ensure first that the item is ready to play, meaning that sufficient data has been buffered by the AVPlayer in order to begin playback. AND I would then want to ensure that playbackLikeyToKeepUp == true so that I can have some degree of certainty that the user's media experience won't be interrupted. But if all you care about is knowing when an item is ready to begin playback again, then you only need check the status.

like image 184
MikeG Avatar answered Oct 22 '22 22:10

MikeG