Ich habe five.caf
Dateien (mit verschiedenen Musiker-Stimme), die ich gleichzeitig mit mehreren Dateien gleichzeitig spielen möchte. Dafür habe ich AVAudioPlayer
Klasse verwendet. Ich habe fünf Instanzen von AVAudioPlayer
erstellt und die URL gesetzt und die Songs abgespielt. Aber es ist nicht richtig synchronisiert. Es sieht so aus, als würde sich die Stimme eines oder zweier Musiker auf eine Sekunde verzögern. Wie kann ich alle Songs gleichzeitig synchronisieren und wiedergeben?Spielen Sie mehrere Songs gleichzeitig
Unten ist der mein 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
Danke für wertvollen Vorschlag. Ich habe deine Lösung ausprobiert, verzögere aber immer noch den Sound wie zuvor. –