R.S.
R.S.

Reputation: 51

Xamarin Apple watch is getting crashed in AVAudioPlayerNode in Release mode

Got below crash in release mode while playing audio.

" * Terminating app due to uncaught exception 'System.Exception', reason: 'Could not create an native instance of the type 'AVFoundation.AVAudioPlayerNode': the native class hasn't been loaded. It is possible to ignore this condition by setting ObjCRuntime.Class.ThrowOnInitFailure to false.' * First throw call stack: ".

While the same working fine with Native AppleWatch OS app.

Public void PlaySound
{

        var audioPlayer = new AVAudioPlayerNode();
        var audioEngine = new AVAudioEngine();
        audioEngine.AttachNode(audioPlayer);

        AVAudioFormat stereoFormat = new AVAudioFormat(44100, 2);
        audioEngine.Connect(audioPlayer, audioEngine.MainMixerNode, stereoFormat);

        NSError error;
        if (!audioEngine.Running)
        {
            audioEngine.StartAndReturnError(out error);
        }

        var filePath = NSBundle.MainBundle.PathForResource("TestAudio","wav");
        var url      = NSUrl.FromString(sFilePath);

        AVAudioFile audioFile = new AVAudioFile(url, out error);

        audioPlayer.ScheduleFile(audioFile, null, null);
        audioPlayer.Play();
}

Upvotes: 0

Views: 88

Answers (1)

R.S.
R.S.

Reputation: 51

This was an issue with the Xamarin for Watch OS, I have logged a bug to Xamarin bugzilla and got a solution for it.

Reply for Xamarin Developer: As a workaround for this bug, try adding the following to the additional mtouch arguments in the project's WatchOS Build options:

-gcc_flags "-framework AVFoundation"

I added this to my WatchExtension's WatchOS build options and this worked like charm.

Latest update from Xamarin is that they have included AVFoundation in their latest simulator.

fixed: https://github.com/xamarin/xamarin-macios/commit/0dd385d81fac0474dbb725b730b4fbb018839a97

Upvotes: 0

Related Questions