Play multiple song simultaneously
<p>I have <strong><code>five.caf</code></strong> files (with different musician's voice) which I want to play at the same time simultaneously with multiple files. For that I have used <code>AVAudioPlayer</code> class. I have created five instance of <code>AVAudioPlayer</code> and set the url and play the songs. But its not sync properly. It looks like one or two musician's voice is delaying unto one second. <strong>How can I sync the all the song at the same time and play them.</strong></p>

<p>Below is the my code:</p>

<pre><code>// Song1
NSString *FilePath = [NSString stringWithFormat:@"%@/songs/%@", [[GlobalClass sharedInstance] GetDocPath], SongFileName];
NSString *url = [FilePath stringByAppendingString:@"/Song1.caf"];
player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:url] error:nil];
[player setDelegate:self];
[player prepareToPlay];
player.numberOfLoops = 0;

// Song2
NSString *url1 = [FilePath stringByAppendingString:@"/Song2.caf"];
player1 = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:url1] error:nil];
[player1 setDelegate:self];
[player1 prepareToPlay];
player1.numberOfLoops = 0;

// Song3
NSString *url2 = [FilePath stringByAppendingString:@"/Song3.caf"];
player2 = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:url2] error:nil];
[player2 setDelegate:self];
[player2 prepareToPlay];
player2.numberOfLoops = 0;

// Song4
NSString *url3 = [FilePath stringByAppendingString:@"/Song4.caf"]; // ALT.caf
player3 = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:url3] error:nil];
[player3 setDelegate:self];
[player3 prepareToPlay];
player3.numberOfLoops = 0;
NSLog(@"player3: %f", player3.duration);

// Song5
NSString *url4 = [FilePath stringByAppendingString:@"/Song5.caf"]; 
player4 = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:url4] error:nil];
[player4 setDelegate:self];
[player4 prepareToPlay];
player4.numberOfLoops = 0;

[player play]; // Band
[player1 play]; // Song1
[player2 play]; // Song2
[player3 play]; // Song3
[player4 play]; // Song4
</code></pre>