我試圖在一次同步使用AVAudioEngine
在iOS的8打數相當長的文件iOS8上AVAudioEngine:適當的方式來播放多個(長)的音頻文件
我可以用下面這樣做:
- (void)startAudio {
AVAudioMixerNode *mainMixer = [self.engine mainMixerNode];
AVAudioPlayerNode *player = [[AVAudioPlayerNode alloc] init];
AVAudioPlayerNode *player2 = [[AVAudioPlayerNode alloc] init];
AVAudioPlayerNode *player3 = [[AVAudioPlayerNode alloc] init];
[self.engine attachNode:player];
[self.engine attachNode:player2];
[self.engine attachNode:player3];
NSString *fileName = [NSString stringWithFormat:@"%@/%@", [[NSBundle mainBundle] bundlePath], @"file1.caf"];
NSURL *fileUrl = [NSURL fileURLWithPath:fileName];
AVAudioFile *file = [[AVAudioFile alloc] initForReading:fileUrl error:nil];
NSString *fileName2 = [NSString stringWithFormat:@"%@/%@", [[NSBundle mainBundle] bundlePath], @"file2.caf"];
NSURL *fileUrl2 = [NSURL fileURLWithPath:fileName2];
AVAudioFile *file2 = [[AVAudioFile alloc] initForReading:fileUrl2 error:nil];
NSString *fileName3 = [NSString stringWithFormat:@"%@/%@", [[NSBundle mainBundle] bundlePath], @"file3.caf"];
NSURL *fileUrl3 = [NSURL fileURLWithPath:fileName3];
AVAudioFile *file3 = [[AVAudioFile alloc] initForReading:fileUrl3 error:nil];
[self.engine connect:player to:mainMixer format:file.processingFormat];
[self.engine connect:player2 to:mainMixer format:file2.processingFormat];
[self.engine connect:player3 to:mainMixer format:file3.processingFormat];
[player scheduleFile:file atTime:nil completionHandler:nil];
[player2 scheduleFile:file2 atTime:nil completionHandler:nil];
[player3 scheduleFile:file3 atTime:nil completionHandler:nil];
NSError *error;
[self.engine startAndReturnError:&error];
[player play];
[player2 play];
[player3 play];
}
但這似乎很繁瑣。我認爲有一種方法可以將節點鏈接在一起,但我找不到任何示例,並且不清楚如何通過觀看AVAudioEngine
上的WWDC會話來執行此操作。
任何想法?
您是否找到解決方案? – ucangetit 2015-06-27 18:28:10