Question

I wanted to add sound effect to my android app. I am using xamarin 4.2 c# and searched examples to do sound effects but could not find one in c# or the one I found had issues.

could some one please show me how to do sound effects in c# in xamarin 4.2; something like playing .mp3 sound for one second without media player pop up.

Was it helpful?

Solution

According to the Xamarin docs it seems to be pretty straightforward:

  1. Create a new Xamarin.Android application named PlayAudio.

  2. Add a sub folder named raw under Resources.

  3. Add a file named test.mp3 under raw.

  4. In the Activity, create a class variable for the MediaPlayer.

    MediaPlayer _player;

  5. In the OnCreate method, call MediaPlayer.Create, passing the context and the resource identifier for the mp3.

    _player = MediaPlayer.Create(this, Resource.Raw.test);

  6. Call the Start method of the MediaPlayer.

    _player.Start();

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top