Sounds, Xamarin

Playing sounds in Xamarin Forms

When we are creating a mobile application we want it to be friendly and intuitive. This is why it is so important to add some sounds to differentiate each action and warn the users using the Application. I’ll teach you how to do this in just three steps.

First of all.. What do I need?

  • Add from NuGet Package the plugin: Xam.Plugin.SimpleAudioPlayer

Let’s Start!

Step 1 Add your audio (You can add it to platform-specific projects or to a shared library):

On the image I show you, for each platform, the name of the folder that you have to place the sound file and the Build Action that you have to set.

Step 2 – Some configuration needed:

First, we need to load the file in a Stream and set your ProyectName.YourSound.ext ,then you have to load the sound (With .Load() Method)  and from here, you will be able to handle the action to the sound. (Play, Stop , Pause,  etc..).

Step 3 – Handling sounds ?:

There are a lot of Methods and Properties to handle the behavior of the sound, I’ll show you some of them bellow:


Done! You can add your prefered sound to your App!

Good luck with your implementation! ?

Spanish post:

https://medium.com/@reyes.leomaris/reproduciendo-sonidos-en-xamarin-forms-12160f24afcb

References:

https://blog.xamarin.com/adding-sound-xamarin-forms-app/?utm_medium=social&utm_campaign=blog&utm_source=linkedin&utm_content=simpleaudioplayer-nuget

Tagged , , , ,

2 thoughts on “Playing sounds in Xamarin Forms

    1. Hi dear! You must be sure that the name of your sound is correct. Let me see how you are putting the Stream line.

Leave a Reply

Your email address will not be published. Required fields are marked *