I am trying to play an mp3 file stored in my SDcard. I am not using an emulator but a Samsung Galaxy S3 with cyanogenmod 13 android 6.0.
First I tried with
Uri.parse(Environment.getExternalStorageDirectory().getPath()+"/gato.mp3")
but the
Environment.getExternalStorageDirectory().getPath()
gets me to /storage/emulated/0.
With the file manager in my phone I see 3 memory storage places:
- Internal storage is located in the /storage/emulated/0.
- sdcard1 is in /storage/FE97-A11B
- secure storage apart.
Which are different from what I see exploring from my computer (only sdcard1 and internal storage).
I couldnt make it work so I put the file "gato.mp3" in both internal and sdcard1, and I can check is there. But with
Environment.getExternalStorageDirectory().getPath()+"/gato.mp3"
which gives me the path /storage/emulated/0/gato.mp3, which should get me to the file, and also trying to set the path manually to /storage/FE97-A11B/gato.mp3, the mediaplayer created with the uri is null, and no file is found. Same if I try the paths I see in the computer explorer.
Anybody has any idea on why it cannot find the file? I have tried removing "/" at the beggining, adding "mnt" to see if i was missing something in the path, but nothing seem to work.
Thank you for your time!
My code to check is just a function
public void ejecutar(View v) {
Uri datos = Uri.parse(Environment.getExternalStorageDirectory().getPath()+"/gato.mp3");
MediaPlayer mp = MediaPlayer.create(this, datos);
if (mp != null) {
mp.start();
}
else{ tv1.setText(datos.toString());}
where tv1 is a textview so i can see which path the uri is pointing to.