I have a directory on my tablet's SD card called "/Android/data/com.example.android.app/files". I just created it manually because I don't know how else to test this aspect of my app. I have filenames stored in a sqlite database like "/folder1/audio1.mp3", "/folder2/audio1.mp3", etc... The files have the same names, but are in different folders, as they are the same thing is different languages. I have those folders (folder1 and folder2) and all of the mp3 files in the "/Android/data/com.example.android.app/files" directory on the SD card.
So, I get the file names from the database and I TRY to get to the folder on the SD card with:
String baseDir = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/data/com.example.android.app/files";
Which just basically ends up making the path "storage/Android/data/com.example.android.app/files".
Now, I DID have a few mp3 files in my raw folder during early development, but there will be too many files in the end to keep in that folder, so I started investigating getting them from the SD card. When I had them in raw, I got them like this:
rid = getResources().getIdentifier(filname, "raw", "com.example.android.app");
Now, with the files on the SD card, that changes to:
filename = "/folder1/audio.mp3"
and instead of "raw" I have:
"storage/Android/data/com.example.android.app/files"
and basically played them like this:
AssetFileDescriptor afd = mContext.getResources().openRawResourceFd(rid);
mMP.reset();
mMP.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getDeclaredLength());
mMP.prepare();
mMP.start();
afd.close();
However none of this approach seems to work the same way now.
Can you get the resourceid from an mp3 file on the SD card? Is that even the appropriate way for me to do it now? Is there a different way I should be playing them that will work whether the source is internal or external memory?
Thoroughly confused.
EDIT:
I did find this which might help...but it's maybe only have of the equation.
EDIT2:
And I'm looking here. It uses mediastore which I don't think is what I want.
See Question&Answers more detail:
os