AVAudioEngine Xamarin.iOS not catched exception engine required running
Asked Answered
S

0

7

I'm using Xamarin.iOS for an application using AVAudioEngine.

Sometimes I get this exception :

AVFoundation_AVAudioPlayerNode_Play Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'required condition is false: _engine->IsRunning()'

This point to my code:

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();
    }
}

I don't understand how is it possible to have this exception that engine is not running, because in my code I Start it and get error if it failed to start ... Then play it.

Also I have a try catch that's not working in this case :( so my applicaton just crashed.

Any advices or idea ?

I comes to this thread but it doesn't help me to understand: https://forums.developer.apple.com/thread/27980

versions:

  • IOS version : 10.3.3

  • Device: ipad 2

  • Xamarin.ios: 11.2.0.11

Thanks

Strobotron answered 17/10, 2017 at 8:8 Comment(2)
What is audioTrack?Darciedarcy
@Darciedarcy I updated my code to add detailsStrobotron

© 2022 - 2024 — McMap. All rights reserved.