Post

Replies

Boosts

Views

Activity

Reply to why AVPlayer sends range
Ok I’ve been solving this problem for a while for my own app so maybe my findings can help others. Note that this has nothing to do with playImmediately() or automaticallyWaitsToMinimizeStalling. Also note that AVPlayer is doing its best with what its parents taught it. First, know that some mp4s and m4as are not made equal; some use different compression than others, that’s what AVPlayer checks for before playing. One of these compression methods is variable bit rate. This is an issue for AVPlayer because while it can maybe know the average bitrate, it can’t calculate the duration of the file. What I believe happens under the hood (based on my own server) is AVPlayer fetches a ridiculous and undefined amount of ranges in order to calculate the final duration. Sometimes it only then starts actually buffering the file. Notice that AVPlayer won’t play or properly buffer until duration > 0. Sometimes (with a remote googlevideo url) it’s even wrong and says the duration is twice what it should be. Yes, this is inefficient. Yes, there are ways to solve this that Apple doesn’t know about since the same url can be played immediately in Chrome, but take 10 seconds in Safari. This is native and expected behaviour for Apple. AVPlayer IS handling a compression it’s not ready for, and DOES eventually succeed in playing it. Good job AVPlayer. Using a different file format will solve this. I’ve yet to find a Swift library that buffers correctly, and has all the benefits of AVPlayer. You can do the conversion serverside at runtime, but if your server is also fetching remotely, I haven’t found a way to convert without also downloading the whole file.
Oct ’24