帮助,AVAudioEngine附加并连接AVAudioUnitSampler可以正常播放。但是在调用AVAudioEngine并再次启动后,播放时崩溃。
我的代码像:
self.engine=[[AVAudioEngine alloc] init];
self.sampler= [AVAudioUnitSampler new];
NSError *error=nil;
NSURL soundfontFileURL = [[NSURL alloc] initFileURLWithPath:[[NSBundle mainBundle] pathForResource:@"test" ofType:@"sf2"]];
[_sampler loadSoundBankInstrumentAtURL:soundfontFileURL program:0 bankMSB:0x79 bankLSB:0 error:&error];
[self.engine attachNode:_sampler];
[self.engine connect:_sampler to:[self.engine outputNode] format:nil];
if([self.engine startAndReturnError:&error]){
NSLog(@"start ok ");
}else{
NSLog(@"start err: %@",error);
}
//play at here is ok.
//[_sampler startNote:60 withVelocity:100 onChannel:0];
[self.engine stop];
if([self.engine startAndReturnError:&error]){
NSLog(@"start ok ");
}else{
NSLog(@"start err: %@",error);
}
//after stop and start again,play crash AudioStreamerImpl::sIOWorkerProcess (17)
[_sampler startNote:60 withVelocity:100 onChannel:0];
崩溃信息:
libEmbeddedSystemAUs.dylib`DLSSample::GetMoreFrames:
AudioStreamerImpl::sIOWorkerProcess(17):EXC_BAD_ACCESS(代码= 1,地址= 0x701c943f1a0)
最佳答案
我的应用程序中存在这样的问题已有几个月了。
经过一些测试,在启动引擎和弹奏音符之间重新加载SoundFont时,似乎没有出现崩溃。
engine.stop()
do {
try engine.start()
reloadSoundFont() // remove this, and there will be the crash with GetMoreFrames()
} catch {
print("Could not start engine: " + error.localizedDescription)
}
self.sampler.startNote(60, withVelocity: 100, onChannel: 0)
delay(1.0) {
self.sampler.stopNote(60, onChannel: 0)
}
关于ios - 停止后,AVAudioEngine连接AVAudioUnitSampler,然后再次启动崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59402729/