I am using multiple instances of AVAudioPlayer to play multiple audio files simultaneously. I run a loop to start playing the audio files (prepareToPlay is called beforehand and the loop only makes a call to the play method)
But invariably, one of the players does not play in sync. How can I ensure that all the 4 players start playing audio simultaneously?
Thanks.
Unfortunately, you can’t. AVAudioPlayer doesn’t provide any mechanism for fine-grained control of start time. The
currentTimeproperty sets the point in the file to read from, it doesn’t guarantee when the AVAudioPlayer instance will start playing in system time, which is what you need to sync multiple audio streams.When I need this behavior, I use the RemoteIO Audio Unit + the 3D Mixer Audio Unit + ExtAudioFile.
EDIT
Note that as of iOS 4, you can synchronize multiple
AVAudioPlayerinstances usingplayAtTime: