我一直在寻找AVAudioEngine,我在整合AVAudioUnitEffect类时遇到了麻烦.例如,使用AVAudioUnitDelay ...
@implementation ViewController {
AVAudioEngine *engine;
AVAudioPlayerNode *player;
}
Run Code Online (Sandbox Code Playgroud)
...
- (IBAction)playButtonHit:(id)sender {
if (!player){
NSURL *bandsURL = [[NSBundle mainBundle] URLForResource:@"Bands With Managers" withExtension:@"mp3"];
AVAudioFile *file = [[AVAudioFile alloc] initForReading:bandsURL error:nil];
engine = [[AVAudioEngine alloc] init];
player = [[AVAudioPlayerNode alloc] init];
[engine attachNode:player];
AVAudioUnitDelay *delay = [[AVAudioUnitDelay alloc] init];
delay.wetDryMix = 50;
[engine connect:player to:delay format:file.processingFormat];
[engine connect:delay to:[engine outputNode] format:file.processingFormat];
[player scheduleFile:file atTime:nil completionHandler:nil];
[engine prepare];
[engine startAndReturnError:nil];
}
[player play];
Run Code Online (Sandbox Code Playgroud)
}
当调用该方法时,应用程序崩溃,我收到此错误:" *因未捕获的异常而终止应用程序'com.apple.coreaudio.avfaudio',原因:'必需条件为false:[_ node containsObject:node1] && [_nodes containsObject :node2]'"
我是在WWDC的"AVAudioEngine in Practice"会议中的一些例子之后对此进行建模的.我知道可能有一些显而易见的东西我不知道但是无法弄清楚......
小智 6
在链接之前,您忘记将AvAudioUnitDelay对象附加到AvAudioEngine节点;)
这是工作代码:
- (IBAction)playMusic:(id)sender {
if (!player){
NSURL *bandsURL = [[NSBundle mainBundle] URLForResource:@"Bands With Managers" withExtension:@"mp3"];
AVAudioFile *file = [[AVAudioFile alloc] initForReading:bandsURL error:nil];
engine = [[AVAudioEngine alloc] init];
player = [[AVAudioPlayerNode alloc] init];
[engine attachNode:player];
AVAudioUnitDelay *delay = [[AVAudioUnitDelay alloc] init];
delay.wetDryMix = 50;
[engine attachNode:delay];
[engine connect:player to:delay format:file.processingFormat];
[engine connect:delay to:[engine outputNode] format:file.processingFormat];
[player scheduleFile:file atTime:nil completionHandler:nil];
[engine prepare];
[engine startAndReturnError:nil];
}
[player play];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3090 次 |
| 最近记录: |