1. PKMousie's Avatar
    I'm writing an app that needs to play a variety of audio samples of different lengths back to back, but only one at a time. The system I came up with works great when using WAV files or whenever running on the simulator no matter what audio type, but on the iPhone itself the logic breaks if I use a compressed audio format like MP3 or AAC. I don't want to ship 5MB of audio when it could be 500K, so this is a serious problem for me!

    I think the bugs have to do with the iPhone's hardware acceleration for compressed audio, and certain playback behaviors changing in this context, but I'm not positive.

    Basically, I have a list of 18 samples. I load each into it's own queueable object with it's own queue reference and buffers. If nothing is playing, I pick the first object randomly and play it, wait for it's queue's isRunning property to go false, then play the next sample upon completion. Fine, right?

    However, when using MP3s, the first sample I play works just fine, but all the other sounds fail to play, stopping immediately (messing up my event logic). Interestingly, when I loop all the way back around to the original sample, it plays again just fine! It doesn't matter which file I play first... the first file always works great, but appears to block the output of all the other sounds that come later, even though it can be correctly played again itself.

    The return codes for all of my AudioQueue calls are 0, even when the audio for a sample doesn't play, and I see a reasonable number of buffering messages as if it's reading and enqueueing each and every file correctly. I'm even flushing the object's queue before calling stop, and resetting the object's queue after the 'isRunning' property goes false, to no avail.

    Can anybody describe the magic incantation that allows multiple compressed audio files to be played through the AudioQueue engine, one at a time, without them blocking each other's output? Am I missing something simple?

    Clues needed!
    2008-08-21 01:04 AM
LINK TO POST COPIED TO CLIPBOARD