Caching behavior of AVURLAsset
Asked Answered
I

1

0

I am using AVURLAsset with various AV/MP player classes and it seems like it is ignoring my server's caching headers. I am working with small, progressively downloaded videos (not HLS).

Is there a way to ensure that videos are cached? Is there a way to pre-cache videos so they play right away? I have experimented with simply changing parameters in NSURLCache, but I haven't had any luck so far. I also can't find any direct way to manipulate how URL fetches are cached by AVURLAsset.

I do not want to download the file separately and point to the local version, because I do not want to wait for the file to be completely downloaded before I can start playing. Ideally, I'd also like to avoid managing a local disk cache myself.

Illation answered 2/3, 2016 at 20:30 Comment(3)
One trick I have seen used before is to split your video into two segments - the first 10 seconds or so, and then the rest. The idea is to traditionally download and save the first file to disk, and stream the other. So you basically make a playlist of two files - the local URL and then the remote one. AVPlayer is smart enough to start buffering the remote stream whilst the local file is playing.Cletacleti
Thanks Matt. I'm not clear how that would work with progressive downloads.Illation
So let's say you're playing a list of 10 small progressive videos. You're probably modeling this as a "playlist" of 10 remote MP4s. What I'm getting at is if you actually download (like NSURLSession download) the first 1 or 2, you now have a playlist that contains two file:// URLs and eight https:// URLs. So assuming you provide the full playlist to AVFoundation at the start, it's smart enough to start buffering your HTTP chunks in the background while the first few play off of disk. Does that make sense?Cletacleti
N
1

There is class called AVAssetResourceLoader. I think you should implement two methods of AVAssetResourceLoaderDelegate

More info here.

Naughty answered 2/3, 2016 at 21:44 Comment(1)
Thanks. I was looking at this, but it didn't seem to implement the right thing -- I will look more carefully.Illation

© 2022 - 2024 — McMap. All rights reserved.