Skip to content
Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
Images reorganizing files into recipes folder Mar 7, 2018
PlayAudio reorganizing files into recipes folder Mar 7, 2018
PlayAudio.sln reorganizing files into recipes folder Mar 7, 2018 fixing broken links Mar 12, 2018

id title brief sdk dateupdated
Play Audio
This recipe shows how to play audio from a raw resource using the MediaPlayer class.


  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;
  1. In the OnCreate method, call MediaPlayer.Create(), passing the context and the resource identifier for the mp3.
_player = MediaPlayer.Create(this, Resource.Raw.test);
  1. Call the Start method of the MediaPlayer.

Additional Information

When the audio to play is included as a resource, the MediaPlayer.Create method can be used to set up the data source to the audio file and prepare the player for playback automatically. If the audio were at a location such as on the web or an SD card, the application would have to set the datasource and call Prepare (or PrepareAsync) before starting playback.

You can’t perform that action at this time.