title: AVAssetReader reads audio, then fails
body: <p>My app reads audio and plays it back in a producer / consumer setup. The consumer thread requests new samples to render to hardware. The producer thread reads audio data from disk into its buffer using AVAssetReader. The producer thread runs in a loop, checking if more samples need to be read. The producer's buffer size is equal to 4 seconds of audio. </p>
  
  <p>When I instruct my app to buffer audio, samples are read successfully without error. When I trigger my producer thread to begin rendering audio, the 4 second buffer is played back perfectly, then silence. Further investigation reveals that my asset reader fails upon the start of playback, thus no further samples where read after the initial buffering: </p>
  
  <pre><code>CMSampleBufferRef ref = [readaudiofile copyNextSampleBuffer];
  if (ref == NULL &amp;&amp; filereader.status == AVAssetReaderStatusFailed) {
      NSLog(@"reader failed: %@", filereader.error);
  }
  // this produces: 
  // {NSLocalizedFailureReason=An unknown error occurred (-12785), 
  // NSUnderlyingError=0x161f60 "The operation couldn’t be completed. 
  // (OSStatus error -12785.)", NSLocalizedDescription=The operation 
  // could not be completed}
  </code></pre>
  
  <p>My producer thread code is identical to the functional code example <a href="http://www.cogs.susx.ac.uk/users/nc81/code.html" rel="nofollow noreferrer">MusicLibraryRemoteIODemo</a>. My consumer thread code is different, but I've compared the two line by line for a couple days and can't seem to find the hitch. Any idea what might be causing the AVAssetReader reader to fail? </p>
  
  <p><a href="https://stackoverflow.com/questions/4763598/avassetreader-and-audio-queue-streaming-problem">This post</a> describes similar solutions and it concluded that the Audio Session needed to be set up properly (although it doesn't say how). Is there any connection between AVAudioSesion configuration and the behavior of AVAssetReader?</p>