I have question about the mp3 playback with the audio queue services.
I've take the SpeakHere Sample, and I just kept the AudioPlayer part since I don't need to record audio.
With it I've been able to play wav files without problem, but that don't work with mp3 or aac files. The playbackCallback function is only called when the setupAudioQueueBuffers is called and never again...
So is their anything I need to change this sample in order to play mp3 files...?
I have question about the mp3 playback with the audio queue services.
I've take the SpeakHere Sample, and I just kept the AudioPlayer part since I don't need to record audio.
With it I've been able to play wav files without problem, but that don't work with mp3 or aac files. The playbackCallback function is only called when the setupAudioQueueBuffers is called and never again...
So is their anything I need to change this sample in order to play mp3 files...?
Thanks
I wouldn't recommend using mp3 period. I don't think the iphone likes mp3 files very well. I would use .caf files for sound only. Just convert your mp3 to caf. It's the best bet since you only can play 5 sec files anyway. Hope this helps.
The fact is that I need to play mp3 since, the user of the application downloads the files before they are played, and mp3 are still one of the smallest audio files.
Maybe I didn't used the right word, by using "sound", since, that's audio files from about 5 to 10 min that I need to play...
You said that I only can play 5 sec files... but AudioQueueServices can play longer files... (the wav I play is about 40s). So I don't understand what you meaned...
I wouldn't recommend using mp3 period. I don't think the iphone likes mp3 files very well. I would use .caf files for sound only. Just convert your mp3 to caf. It's the best bet since you only can play 5 sec files anyway. Hope this helps.
StrAbZ is using the Audio Queue services which can play sounds without a time limit....
Starbz I had the same problem as you... and the answer couldn't even be answered on the apple support forums. I decided to go with aif.. MP3 or AAC would be better for me since I can make the file sizes very small.
I hope you find the answer ... if you do, please share with us. I'll be researching it also.
The fact is that I need to play mp3 since, the user of the application downloads the files before they are played, and mp3 are still one of the smallest audio files.
Maybe I didn't used the right word, by using "sound", since, that's audio files from about 5 to 10 min that I need to play...
You said that I only can play 5 sec files... but AudioQueueServices can play longer files... (the wav I play is about 40s). So I don't understand what you meaned...
thank u
Oh... Sorry, I missed the part of (AudioQueueServices) lol... Yea, you should be able to use mp3 in it. I've always been told to stay away from mp3 on the iphone. So that's why I convert everything but in your case you said you need it because of file size. I don't see why you couldn't use AAC? AAC isn't that far off from mp3 in size.
Anyways, have a look at this link. It should help you.
Oh... Sorry, I missed the part of (AudioQueueServices) lol... Yea, you should be able to use mp3 in it. I've always been told to stay away from mp3 on the iphone. So that's why I convert everything but in your case you said you need it because of file size. I don't see why you couldn't use AAC? AAC isn't that far off from mp3 in size.
Anyways, have a look at this link. It should help you.
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!