If you wish to play more audio streams simultaneously, synced using AVAudioPlayer, well under iOS 4 and above you won’t have any problem, because it features the playAtTime: method with example and clear documentation.
However, if you wish to do the same on iOS 3.x, then you have to check AudioQueue.
The most important part of syncing is the good timing, which should be set in the same way as with playAtTime and has to be specified as the second parameter of
AudioQueueStart (AudioQueueRef inAQ, const AudioTimeStamp *inStartTime) and not in AudioQueueEnqueueBufferWithParameters. To specify the exact start time of AudioQueue, use the
FillOutAudioTimeStampWithHostTime method with an
To retrieve the base time, use
CAHostTimeBase from iPublicUtility.
Simultaneous MP3 playback works well in emulator, however on the real device, the hardware decoder can decode only 1 MP3 at a time, so you have to use software decoders. (by default AudioQueue uses the hardware decoder only)
To enable software decoding on an AudioQueue, set the kAudioQueueHardwareCodecPolicy property to
However to optimize battery life and use less CPU, you can enable hardware decoding on one of the AudioQueues, by setting the property to: