AVPlayer unpredictable range requests on iOS when streaming *.mov file

Hi all,

I'm trying to diagnose and resolve an issue with stuttering video playback using the standard AVPlayer. The video in question is a 4K, 39-second file in *.mov format, being played on an iOS device. It's served via a local HTTP server that proxies requests to a backend to fetch and process the content. The project uses end-to-end encrypted storage, which necessitates the proxy for handling data processing. While playback in offline scenarios is smooth, we are encountering issues with smooth playback during streaming. The same video streams smoothly on other platforms using the same connection, so network limitations are not a factor.

On iOS, playback is consistently choppy, with pauses every 1-3 seconds. The video does not appear to buffer adequately for smooth playback.

One particularly curious aspect is the seemingly random pattern of Content-Range requests made by the AVPlayer when streaming the video. Below is an example of the range requests:

There's frequent jumping between ranges, such as from 80MB to 40MB and back again: 

```language
Content-Range: bytes 74121216-74186751/306060181
Content-Range: bytes 47841280-54525951/306060181
Content-Range: bytes 80805888-80871423/30606018

In contrast, the same video, when played on macOS 14.6.1 (23G93) using QuickTime and the same HTTP server and connection, results in far simpler requests:

Content-Range: bytes 0-1/306060181
Content-Range: bytes 305987584-306060180/306060181
Content-Range: bytes 4184448-305987583/306060181

As you can see, it's much simpler to handle by the streaming server.

This makes it much easier for the server to handle.

Here are my questions:

  1. What governs the logic for the range requests made by AVPlayer? Is this documented anywhere?
  2. Can the request logic be influenced to make it more linear using AVPlayer, AVPlayerItem configuration, or the AVAssetResourceLoaderDelegate?
  3. If range-request logic cannot be changed, what is the best approach to buffer data on the client to ensure smooth playback for AVPlayer?

Here's missing log that was "sensitive" according to the validator and I could not attach it

4K
Content-Range: bytes 0-1/306060181
Content-Range: bytes 305987584-306060180/306060181
Content-Range: bytes 16384-305987583/306060181
Content-Range: bytes 28901376-305987583/306060181
Content-Range: bytes 34471936-34537471/306060181
Content-Range: bytes 41287680-41353215/306060181
Content-Range: bytes 27262976-28049407/306060181
Content-Range: bytes 47710208-47775743/306060181
Content-Range: bytes 26017792-27262975/306060181
Content-Range: bytes 47775744-47841279/306060181
Content-Range: bytes 28114944-34471935/306060181
Content-Range: bytes 54525952-54591487/306060181
Content-Range: bytes 61014016-61079551/306060181
...
AVPlayer unpredictable range requests on iOS when streaming *.mov file
 
 
Q