'How to receive a push notification and play a sound file?

I want to play an alarm sound file when the App receive push notification. Here's my alarm function.

   private void PlayAlarm()
    {
        var assembly = typeof(App).GetTypeInfo().Assembly;
        Stream audioStream = assembly.GetManifestResourceStream("MyApp.Assets.Sounds." + "emergencyalert.wav");

        var player = Plugin.SimpleAudioPlayer.CrossSimpleAudioPlayer.Current;
        player.Loop = true;
        player.Volume = 1;
        player.Load(audioStream);
        player.Play();
        player.Play();

    }

My question, is that possible to play my alarm when a push notification received? or is there a best way to activate the "PlayAlarm" method when some sort of notification received?

The idea I got is from the "Skype" App, so when the App receive a call then it will play the phone ring sound.

Is it possible to implement in Xamarin or should I dive into native app like "swift" and "android" to achieve this?

I want all the phone that installed the App to activate the alarm sound when they receive a push notification or something similar.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source