title: AVAssetResourceLoaderDelegate - Only requests first two bytes?
body: <p>I'm implementing an <code>AVAssetResourceLoaderDelegate</code>, and I'm having a bit of trouble getting to to behave correctly.  My goal is to intercept any requests made by the AVPlayer, make the request myself, write the data out to a file, then respond to the <code>AVPlayer</code> with the file data.</p>
  
  <p><strong>The issue I'm seeing</strong>: I can intercept the first request, which is only asking for two bytes, and respond to it.  After that, I'm not getting any more requests hitting my <code>AVAssetResourceLoaderDelegate</code>.</p>
  
  <p>When I intercept the very first <code>AVAssetResourceLoadingRequest</code> from the <code>AVPlayer</code> it looks like this:</p>
  
  <pre><code>&lt;AVAssetResourceLoadingRequest: 0x17ff9e40, 
  URL request = &lt;NSMutableURLRequest: 0x17f445a0&gt; { URL: fakeHttp://blah.com/blah/blah.mp3 },
  request ID = 1, 
  content information request = &lt;AVAssetResourceLoadingContentInformationRequest: 0x17ff9f30,
  content type = "(null)",
  content length = 0,
  byte range access supported = NO,
  disk caching permitted = NO&gt;,
  data request = &lt;AVAssetResourceLoadingDataRequest: 0x17e0d220,
  requested offset = 0, 
  requested length = 2, 
  current offset = 0&gt;&gt;
  </code></pre>
  
  <p>As you can see, this is only a request for the first two bytes of data.  I'm taking the <code>fakeHttp</code> protocol in the URL, replacing it with just <code>http</code>, and making the request myself.</p>
  
  <p>Then, here's how I'm responding to the request once I have some data:</p>
  
  <pre><code>- (BOOL)resourceLoader:(AVAssetResourceLoader *)resourceLoader shouldWaitForLoadingOfRequestedResource:(AVAssetResourceLoadingRequest *)loadingRequest {   
  
       //Make the remote URL request here if needed, omitted
  
      CFStringRef contentType = UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, (__bridge CFStringRef)([self.response MIMEType]), NULL);
      loadingRequest.contentInformationRequest.byteRangeAccessSupported = YES;
      loadingRequest.contentInformationRequest.contentType = CFBridgingRelease(contentType);
      loadingRequest.contentInformationRequest.contentLength = [self.response expectedContentLength];
  
      //Where responseData is the appropriate NSData to respond with
      [loadingRequest.dataRequest respondWithData:responseData];
  
      [loadingRequest finishLoading];
      return YES;
  }
  </code></pre>
  
  <p>I've stepped through this and verified that everything in the <code>contentInformationRequest</code> is filled in correctly, and that the data I'm sending is NSData with the appropriate length (in this case, two bytes).</p>
  
  <p>No more requests get sent to my delegate, and the player does not play (presumably because it only has two bytes of data, and hasn't requested any more).</p>
  
  <p>Does anyone have experience with this to point me toward an area where I may be doing something wrong?  I'm running iOS 7.</p>
  
  <p><strong>Edit:</strong>  Here's what my completed request looks like, after I call <code>finishedLoading</code>:</p>
  
  <pre><code>&lt;AVAssetResourceLoadingRequest: 0x16785680,
  URL request = &lt;NSMutableURLRequest: 0x166f4e90&gt; { URL: fakeHttp://blah.com/blah/blah.mp3  },
  request ID = 1,
  content information request = &lt;AVAssetResourceLoadingContentInformationRequest: 0x1788ee20,
  content type = "public.mp3",
  content length = 7695463,
  byte range access supported = YES,
  disk caching permitted = NO&gt;,
  data request = &lt;AVAssetResourceLoadingDataRequest: 0x1788ee60,
  requested offset = 0,
  requested length = 2,
  current offset = 2&gt;&gt;
  </code></pre>