Let’s start with the simplest example. The program will immediately play the MP3 file that will be within the program itself.

We start by creating a project and creating a subdirectory called “raw” in the “res” directory of the project. Then to the raw subdirectory we put the music in any of the formats: wav, aac, mp3, wma, amr, ogg, midi

Everything we put into the res subdirectory is automatically recorded as a resource available from the code level.

Now just a little bit of the main activity code:

The key lines are 19-21. I was joking 🙂 We are interested in lines 16 and 17. On line 16 we create a MediaPlayer object which is used for media playback. When we create, we pass as the arguments for the create method: kontekts and resource. As you can see, we do not provide a file extension.

Line 17 is the playback of the resource we indicated on line 16.

If the music file we wanted to play was outside of the application, eg on the SD card, our code would look like this:

MediaPlayer mp = new MediaPlayer ();

mp.setDataSource ( “/ sdcard / Tickets / raise_raise.mp3”);

mp.prepare ();

mp.start ();