AVAudioEngine Xamarin.iOS没有捕获异常引擎所需的运行

Jer*_*606 7 c# xamarin.ios ios xamarin avaudioengine

我正在使用Xamarin.iOS作为使用AVAudioEngine的应用程序.

有时我得到这个例外:

AVFoundation_AVAudioPlayerNode_Play由于未捕获的异常'com.apple.coreaudio.avfaudio'而终止应用程序,原因:'必需条件为false:_engine-> IsRunning()'

这指向我的代码:

private Dictionary<AudioTrack, AVAudioPlayerNode> _dicPlayerNodes;
private void PlayAudio()
{
    try
    {
        NSError err;
        if (Engine.StartAndReturnError(out err))
        {
            foreach (var audioTrack in _dicPlayerNodes)
            {
                 AVAudioPlayerNode node = audioTrack.Value;
                 node.Play();
            }
        }
        else
        {
            Messenger.Publish(new AudioErrorMessage(this) { Platform = "IOS", Code = Convert.ToInt32(err.Code), Message = err.LocalizedDescription ?? err.Description });

            _exceptionHandlerService.PostHockeyApp(new Exception($"{err.Code} {err.Description}"));
        }
    }
    catch (Exception ex)
    {
        _exceptionHandlerService.PostExceptionAsync(ex).Forget();
    }
}
Run Code Online (Sandbox Code Playgroud)

我不明白怎么可能有这个异常引擎没有运行,因为在我的代码中我启动它并获得错误,如果它无法启动...然后播放它.

此外,我有一个尝试捕获在这种情况下不工作:(所以我的应用程序刚刚崩溃.

有什么建议或想法吗?

我来到这个主题,但它无法帮助我理解:https: //forums.developer.apple.com/thread/27980

版本:

  • IOS版本:10.3.3

  • 设备:ipad 2

  • Xamarin.ios:11.2.0.11

谢谢