How to beep? - Xamarin Forms

-1

I need to sound (beep) on the Smartphone to get the user's attention, I'm just testing for a button initially. The codes I've tested only give error, the last one being the here link. What I did from what I understand is below:

   //Botão Som
        private void Som_Clicked(object sender, EventArgs e)
        {
            var player = Plugin.SimpleAudioPlayer.CrossSimpleAudioPlayer.Current;
            player.Load("Glass_audio.mp3");

            player.Play();
            Task.Delay(10000);
        }

Theerror:

    
asked by anonymous 23.07.2018 / 15:09

2 answers

0

The beep function is not compatible with the Android platform.

To run a warning sound on Android follow this guide.

    
23.07.2018 / 15:15
0

In the System.Media namespace there is a class called SystemSounds, which contains methods to execute the main sounds associated with Windows (Beep, Asterisk, Question, Exclamation and Hand).

So just use this class to play the sound you want.

using System.Media;

public class MinhaClasse
{
public void TocarBeep()
{
    // Toca o som associado ao Beep, no Windows
    SystemSounds.Beep.Play();
}
}

There may be an error caused by the OS version used. In that case something more specific should be used.

    
23.07.2018 / 15:15