How can I cache only the initial few seconds (chunks) of an HLS stream on the disk?

Hi, I am working on an app that is very similar to TikTok in terms of video experience. There is an infinite scroll feed of videos, and I am using HLS URLs as the video source.

My requirement is to cache the initial few seconds of each video on the disk while the video is playing. The next time a user views the video, it should play the initial few seconds from the cache, with the subsequent chunks coming from the network. Additionally, when there is no network connection, the video should still play the initial few seconds from the cache.

I was able to achieve this with MP4 using AVAssetResourceLoaderDelegate, but the same approach is not possible with HLS.

What are some other ways through which I can implement this feature?

Thanks.

This sample code may help.

Well, I have achieved this via using reverse proxy server implementation. The above code didn't necessarily work for my needs. Let me know if anyone wants to know further detail s on that.

Hi @iamskk Can you share me the sample code how you manage to cache only first few seconds code.

How can I cache only the initial few seconds (chunks) of an HLS stream on the disk?
 
 
Q