我尝试使用RenderToFile导出音频,但是当设置了ScheduledTime时,它不起作用

时间:2019-06-13 07:59:02

标签: swift audiokit

我合并了两个音频,其中一个设置了ScheduledTime。当我播放时,它起作用。但是,当我使用RenderToFile导出并开始播放导出的音频时,scheduleTime不起作用。

NSString *path1 = [[NSBundle mainBundle]pathForResource:@"test" ofType:@"mp4"];
NSString *path2 = [[NSBundle mainBundle]pathForResource:@"music_1" ofType:@"mp3"];

AKAudioFile *file1 = [[AKAudioFile alloc]initForReading:[NSURL fileURLWithPath:path1] error:nil];
AKAudioFile *file2 = [[AKAudioFile alloc]initForReading:[NSURL fileURLWithPath:path2] error:nil];

AKAudioPlayer *player1 = [[AKAudioPlayer alloc]initWithFile:file1 looping:NO lazyBuffering:YES error:nil completionHandler:nil];
AKAudioPlayer *player2 = [[AKAudioPlayer alloc]initWithFile:file2 looping:NO lazyBuffering:YES error:nil completionHandler:nil];

player2.scheduledTime = player1.duration;
AKMixer *mixer = [[AKMixer alloc]init:@[player1,player2]];
AudioKit.output = mixer;

AVAudioFormat *format = [[AVAudioFormat alloc]initWithCommonFormat:AVAudioPCMFormatFloat64 sampleRate:44100 channels:2 interleaved:NO];
NSMutableDictionary *settings = [NSMutableDictionary dictionaryWithDictionary:format.settings];
[settings setObject:@(kAudioFormatMPEG4AAC) forKey:AVFormatIDKey];
AKAudioFile *file = [[AKAudioFile alloc]initForWriting:[NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/justTest.aac",MineAudioURL]] settings:settings error:nil];

[AudioKit renderToFile:file duration:player1.duration+player2.duration error:nil prerender:^{
   [player1 start];
   [player2 start];
}];

当我播放时,player2将在player1完成后播放。但是,当我使用RenderToFile导出并开始播放导出的音频时,两者都同时播放。这不是我想要的。我想在audio2完成后播放audio1

0 个答案:

没有答案