I know the answer for you, I think! But I can only get you so far... since even though I can now play MP3 files perfectly on the simulator,
I'm still having trouble getting them to behave correctly on the phone. But I CAN get at least one to play on the phone itself... so I know I'm 99% of the way there.
The SpeakHere sample (which I used as well, leading to much frustration) leaves out a hugely important piece of code. You need to manually allocate the package decriptions for VBR content... and AAC/MP3 files are always considered VBR even if they're encoded CBR!!! Here's the test and allocation:
Code:
// Test for VBR format files, which need extra initialization
if (audioFormat.mBytesPerPacket == 0 || audioFormat.mFramesPerPacket == 0) {
packetDescriptions = (AudioStreamPacketDescription*)malloc(
numPacketsToRead * sizeof(AudioStreamPacketDescription)
);
} else {
packetDescriptions = NULL;
}
Just stick a version of this somewhere in your code, after you've loaded the audio format information and calculated your packets to read and buffer sizes, but before you read and enqueue the data. It's all spelled out in the documentation, but it's easy to miss or think you don't need it (like I did). Once I added this allocation step, MP3s play just fine in the simulator! Woo!
Audio Queue Services Guide - Set Sizes for a Playback Audio Queue
I hope this helps, or helps anyone else who stumbles across your post when trying to figure this stuff out like I did!
And maybe now someone else can help me with
my problem!