0

I have an audio file on drawable folder.

Suppose that the filename is: "abc.mp3".

I would use this code to reproduce the sound:

MediaPlayer mPlayer = MediaPlayer.create(this, Uri.parse("pathFile"));

What's the path of my file?

Thank you!

user3253955
  • 433
  • 1
  • 8
  • 17

2 Answers2

1

If you don't want to place the audio file in the assets folder, you can place it in the "raw" folder inside the resources folder. Thus, /res/raw. Then access it like this:

MediaPlayer mPlayer = MediaPlayer.create(this, R.raw.abc);

// enable loop and play
mPlayer.setLooping(true);
mPlayer.start();
Nana Ghartey
  • 7,901
  • 1
  • 24
  • 26
0

You should be placing audio file in the assets folder, not in the drawable folder.

After placing your file in the assets folder you can follow this SO post : Play audio file from assets directory.

Community
  • 1
  • 1
Ovidiu Latcu
  • 71,607
  • 15
  • 76
  • 84