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 as
You cannot get the resource ID for an mp3 in your SD card, because this mp3 does not belong to the resources folder in your project and therefore has no resource ID.
From the Android Developers Guide:
When your application is compiled, aapt generates the R class, which contains resource IDs for all the resources in your res/ directory.
In order to be able to play mp3 from both the internal memory and the SD card, you can do something like this:
try {
FileDescriptor fd = null;
if (isInInternalMemory(audioFilename)) {
int audioResourceId = mContext.getResources().getIdentifier(audioFilename, "raw", "com.ampirik.audio");
AssetFileDescriptor afd = mContext.getResources().openRawResourceFd(audioResourceId);
fd = afd.getFileDescriptor();
} else if (isInSdCard(audioFilename)) {
File baseDir = Environment.getExternalStorageDirectory();
String audioPath = baseDir.getAbsolutePath() + audioFilename + ".mp3";
FileInputStream fis = new FileInputStream(audioPath);
fd = fis.getFD();
}
if (fd != null) {
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setDataSource(fd);
mediaPlayer.prepare();
mediaPlayer.start();
}
} catch (Exception e) {
e.printStackTrace();
}
This is only an example to show how it could work, obviously you should tweak it to point to the folder where your audio file is stored and handle in a proper way the exceptions you need.
EDIT: Also, you can see a more complex example of how to play audios from the SD card here: https://github.com/ankidroid/Anki-Android/blob/develop/AnkiDroid/src/main/java/com/ichi2/libanki/Sound.java