首页 > 解决方案 > 在主机应用程序 (iOS) 中检测 AUv3 失效

问题描述

我正在开发一个 AUv3 主机应用程序,我希望在加载的音频单元由于某种原因崩溃(失效)时通知用户。我查看了 Apple 关于 AUAudioUnit 的文档,但找不到任何有关如何从主机应用程序检测音频单元 (AUv3) 失效的信息。

有谁知道如何做到这一点?

谢谢

标签: objective-cswiftaudiounitauv3

解决方案


在设置 AudioEngine 时,您可以观察kAudioComponentInstanceInvalidationNotification以确定其音频组件实例是否稍后失效。

[[NSNotificationCenter defaultCenter] addObserverForName:kAudioComponentInstanceInvalidationNotification object:nil queue:nil usingBlock:^(NSNotification *note) {

    AUAudioUnit *auUnit = (AUAudioUnit *)note.object;

    NSValue *val = note.userInfo[@"audioUnit"];
    AudioUnit auAddress = (AudioUnit)val.pointerValue;

    NSLog(@"AudioComponent Invalidation of Unit:%@ with Address:%p", auUnit, auAddress);

}];

请记住,您可能已经收到通知,但组件最终陷入了死锁。因此,当您试图从中恢复时,您可能不得不关闭整个主机应用程序。


推荐阅读