1

I want to integrate my app with a MediaPlayer, but I can't play music that are in the internal storage. Actually I have only 1 song in the "Music" folder. I can't play it. This is my code:

Uri uri = MediaStore.Audio.Media.INTERNAL_CONTENT_URI;
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC;
try {
    mediaPlayer.setDataSource(this, uri);
    mediaPlayer.prepare();
} catch (IOException e) {
    e.printStackTrace();
}
mediaPlayer.start();
Deca
  • 153
  • 1
  • 11

1 Answers1

0

This techniques is ok if and only if you want to play one sound depending on your condition. Set URI as follow:

Uri soundUri = Uri.parse("android.resource://" + getPackageName()
                + "/" + R.raw.sound);

other way would be:

Uri uri = MediaStore.Audio.Media.getContentUriForPath(pathToFolderSDCard);  
surhidamatya
  • 2,419
  • 32
  • 56