title: AudioPlayer iOS and m4a
body: <p>I've made an app that plays music using AVAudioPlayer. It either uploads or downloads songs, writes them to Core Data, then recalls them to play when selected. All of the fifteen songs that I've been testing with operate normally using both the iPhone Music Client and my own computer.</p>
  
  <p>However, three of them don't play back on the app. Specifically, I can upload these fifteen songs in any order, clear my Model.sqlite, download them again into the app, and find that three of them just don't play. They do, however, have the right title and artist.</p>
  
  <p>Looking into this, I noticed that the difference is that the non-working files are .m4a. How do I play files of that format with AVAudioPlayer?</p>
  
  <p>EDIT ("Whats "recalling?", what URL do you initialise AVAudioPlayer with?"):</p>
  
  <p>There is a server with songs that the user can access through the app. After choosing which subset S to retrieve, the app then downloads S and writes it to a CoreModel using NSManagedObjectContext. Each song is stored as a separate entity with a unique ID and a relationship to a subset entity (in this case, S).</p>
  
  <p>When I "recall" using the AppDelegate to get the right song using the context, the data is returned as well. I then initialize the AVAudioPlayer like so:</p>
  
  <pre><code>[[AVAudioPlayer alloc] initWithData:(NSData *)[currentSong valueForKey:@"data"] error:nil];
  </code></pre>
  
  <p>... So I wrote that and then realized that I haven't actually checked out what the error is (silly me). I found that it's <code>OSStatus error 1954115647</code>, which returns as Unsupported File Type. Looking into this a bit more, I found this <a href="https://stackoverflow.com/questions/4901709/iphone-avaudioplayer-unsupported-file-type">iPhone: AVAudioPlayer unsupported file type</a>. A solution is presented there as either trimming off bad data in the beginning or initializing from the contents of a URL. Is it possible to find where the data is written to in core model to feed that as the URL?</p>
  
  <p>EDIT: (Compare files. Are they different?)</p>
  
  <p>Yes, they are. I'm grabbing a sample .m4a file from my server, which was uploaded by the app, and comparing it to the one that's in iTunes. What I found is that the file is cut off before offset 229404 (out of 2906191 bytes), which starts <code>20680001 A0000E21</code>. In the iTunes version, <code>0028D83B 6D646174</code> lies before those bytes. Before that is a big block of zeroes preceded by a big block of data preceded by iTunes encoding information. At the very top is more encoding information listing the file as being M4A. </p>