0

I found this tutorial and am trying to implement it in my project http://www.androiddevblog.net/android/playing-audio-in-android

I want to read music from res/raw folder instead of external storage

Cursor cursor = getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, null, null, null, null);

Here is my code:

Cursor cursor = getContentResolver().query( MediaStore.Audio.Media.getContentUri("android.resource://com.varma.samples.musicplayer/raw/"), null, null, null, null);

Of course the Uri does not return anything and I want to get the audio from res/raw...

Thank you!!


EDIT:

Thank you both, I won't use a cursor then ;)

If it helps somebody I am using this for get all songs:

Field[] fields = R.raw.class.getFields();
  • check my answer here. There's no need for the use of the Cursor because you are getting the audio file from your raw file. http://stackoverflow.com/questions/11093157/java-playing-a-sound-effect/11093521#11093521 – Kurty Jun 22 '12 at 19:52

1 Answers1

1

There is no need to use a Cursor here.

Please search in the official developer docs before posting your question here. Specifically the Media Playback page contains an example for how to do what you are trying.

MediaPlayer mediaPlayer = MediaPlayer.create(context, R.raw.sound_file_1);
mediaPlayer.start(); // no need to call prepare(); create() does that for you
FoamyGuy
  • 46,603
  • 18
  • 125
  • 156