I am quite new to Android-Development. I have troubles to access my songs, stored in the Music folder. From adb shell the path is: /storage/emulated/legacy/Music. Following code causes the exception:
try {
Log.i("path", Environment.getExternalStorageDirectory().getAbsolutePath()+"/"+Environment.DIRECTORY_MUSIC + "/" + name + ".mp3");
mediaPlayer.setDataSource(getApplicationContext(),
Uri.parse(Environment.getExternalStorageDirectory().getAbsolutePath()
+ "/"
+ Environment.DIRECTORY_MUSIC
+ "/"
+ name + ".mp3"));
mediaPlayer.prepare();
mediaPlayer.start();
}
Here is the exception:
I/path: /storage/emulated/0/Music/A Wunder.mp3
java.io.IOException: setDataSource failed.
Any help appreciated!
EDIT: It seems that i have problems with some of the files. My "Player" can‘t open all of them, but other player can. So here is the code that works for me:
mediaPlayer.setDataSource(getApplicationContext(),
Uri.parse(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC) + "/" + name + ".mp3"));