title: Is it possible to cache HLS segments with AVPlayer?
body: <p><strong>Root Problem​</strong></p>
  
  <p>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.</p>
  
  <p><strong>​Desired Solution​</strong></p>
  
  <p>Caching the video segments locally on the device's disk. We're fine with caching a single quality and always replaying it.</p>
  
  <p><strong>​Blocker​</strong></p>
  
  <p>We can't find a way to perform caching within AVFoundation/AVPlayer.</p>
  
  <p><strong>What We've Tried</strong></p>
  
  <p>2 ways to intercept networking requests with AVPlayer.</p>
  
  <ol>
  <li>Conforming to ​AVAssetResourceLoaderDelegate ​and handling the loading of the media manually</li>
  </ol>
  
  <p>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:
  <a href="https://gist.github.com/nathanhillyer/84e46152d7c4c88183b6" rel="noreferrer">https://gist.github.com/nathanhillyer/84e46152d7c4c88183b6</a></p>
  
  <ol start="2">
  <li>Implementing a NSURLProtocol ​to capture requests for <code>.ts</code> files.</li>
  </ol>
  
  <p>AVURLAsset actually avoids being intercepted. Somehow the network requests just don't get captured. (No clue why)</p>