How to sound (beep)? - Xamarin Forms

Asked

Viewed 464 times

-1

I need to sound (beep) on the Smartphone to get the user’s attention, I’m testing only by a button initially. The codes I have tested only gives error, the last is being link here. What I did I understood 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);
        }

inserir a descrição da imagem aqui

The mistake:

inserir a descrição da imagem aqui

  • The message seems very clear to me: the operation is not supported by the platform. Where is it running? It should support?

  • Sorry, I had not specified well. Read the description now that you can understand better.

2 answers

0

In the System.Media namespace has a class called Systemsounds, which contains methods to perform 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 error caused by the version of the OS used. In this case something more specific should be used.

  • Sorry, I had not specified well, now I modified the question.

  • 2

    I have searched, you will find the answer here - http://www.macoratti.net/16/07/xamand_som1.htm

  • This link is explained more about Xamarin Android, I need it to be Xamarin Forms. I have this link and am testing: https://blog.xamarin.com/adding-sound-xamarin-forms-app/

  • I modified the question to update the tests I’ve been doing, if there’s anything I can do to help.

  • 3

    I work with desktop, but this kind of error of not found when a file is inserted is solved by copying to the debug folder while maintaining the same folder structure. In case copy the sound file into the "Assets" folder that is in the debug folder. You can also test select "Always copy" instead of "Do not copy" in the mp3 file properties.

  • Thanks, it worked by following the link I left in the question.

Show 1 more comment

0


The beep function is not compatible with Android platform.

To run a warning sound on Android follow this guide.

  • Sorry, I had not specified well, now I modified the question.

  • 1

    The beep command is not compatible with Android devices, if you have to run this on an Android will give this error because it is not supported on that platform.

  • Add a guide that you can follow to add a sound library for use on Android

  • It really seems that this link will be the answer I need, I’m just not getting to finish the test once, I modified the question again because of the advances in the test, if I can help in something I’m grateful.

  • Just to be clear, in the first image when clicking inside the folder Assets -> Glass_audio.mp3 -> Ação de Compilação -> Not choose the Recurso Inserido (as it is in the image), but AndroidAsset. It won’t work for Genymotion, only for the physical device.

  • What options do you have in "Build Action"?

  • And make sure you’re entering the name correctly. "Glass_audio.mp3" is case sensitive so check the upper case as well.

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.