Root Problem
Our video buffers a lot when seeking in iOS. It buffers quite a bit more than our web player which saves copies of the already watched segments in temp storage.
Desired Solution
Caching the video segments locally on the device's disk. We're fine with caching a single quality and always replaying it.
Blocker
We can't find a way to perform caching within AVFoundation/AVPlayer.
What We've Tried
2 ways to intercept networking requests with AVPlayer.
- Conforming to AVAssetResourceLoaderDelegate and handling the loading of the media manually
Doesn't work with HLS. You can load the m3u8 files by implementing AVAssetResourceLoaderDelegate, which allows you to pass authentication or to decrypt the response, however the .ts files can't be loaded. Here's the code we tried: https://gist.github.com/nathanhillyer/84e46152d7c4c88183b6
- Implementing a NSURLProtocol to capture requests for
.tsfiles.
AVURLAsset actually avoids being intercepted. Somehow the network requests just don't get captured. (No clue why)
.tsfiles. @narohi - Did you ever figure this out? I also really want to cache HLS segments on disk. Glad to find out that it won't work before I waste my time. Right now I'm leaning towards droppingAVPlayer, and just writing my own HLS player by parsing them3u8playlists and usingAVQueuePlayer. JWPlayer SDK for iOS looks promising, but their "contact us for our annual contract pricing" sounds a bit scary. - ndbroadbentAVPlayerItemStatus.Failedafter I callfinishLoading()on the request, and the error is just:The operation could not be completed- ndbroadbent