Playing fMP4 Raw Chunks in AVPlayer on iOS

Hello Apple Community, We are working on a real-time streaming feature where we receive chunks of raw MP4 data through a custom protocol and store them in a buffer (array). Our goal is to use these data chunks to play a continuous video stream in AVPlayer.

What We've Tried:

  1. Custom URL Scheme with AVAssetResourceLoaderDelegate:
  • We implemented a custom URL scheme (customscheme://) to serve the buffered data using AVAssetResourceLoaderDelegate.

  • The method shouldWaitForLoadingOfRequestedResource is called only during the initial allocation. It doesn't get triggered when new chunks are appended to the buffer.

  • Despite appending new data to the buffer, AVPlayer doesn’t request further chunks from the delegate.

What We Need:

We are looking for a solution where:

  1. The player continuously fetches data from the buffer as new chunks are added.

  2. The playback remains smooth and uninterrupted, even with real-time data being appended.

  3. Ideally, this solution works with AVPlayer while adhering to HLS-like behavior without implementing an HLS server.

Questions:

  1. Is AVAssetResourceLoaderDelegate the right approach for this use case?
  • If so, how can we ensure shouldWaitForLoadingOfRequestedResource is called whenever new data is available in the buffer?
  1. Are there alternative APIs or recommended patterns for playing real-time MP4 data chunks in AVPlayer?

  2. Would implementing a custom FFmpeg-based player be necessary, or can this be achieved using AVPlayer and its APIs?

We appreciate any guidance, suggestions, or examples that can help us achieve this. Thank you!