Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

Thread: Mp3 Playback
View Single Post
Old 08-20-2008, 01:08 PM   #10 (permalink)
PKMousie
Code Monkey
 
Join Date: Aug 2008
Location: San Jose
Posts: 8
Default

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!
PKMousie is offline   Reply With Quote
 

» Advertisements
» Stats
Members: 158,868
Threads: 89,225
Posts: 380,691
Top Poster: BrianSlick (7,129)
Welcome to our newest member, stokesreece
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 06:16 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.