I want to play audio files from memory card.
How to get external sdcard path in android programming?
Unfortunately, every android phone model has a different path.for example:
Galaxy S3 android 4.4: memory card exists in the path: "/mnt/extSdCard/"
Honor 7c android 8: memory card exists in the path: "/mnt/ext_sdcard/"
I couldn't find the path in Nokia 5 with android 9 and Xiaomi Redmi 3s with android 6.
try {
File root = Environment.getExternalStorageDirectory();
String audioPath = root.getAbsolutePath() + "/telavatquran/naba.mp3";
FileInputStream fis = new FileInputStream(audioPath);
fd = fis.getFD();
if (fd != null) {
player.setDataSource(fd);
player.prepare();
player.start();
} else if (new File("/mnt/sdcard/external_sd/").exists()) {
seekUpdation();
player.setDataSource("/mnt/sdcard/external_sd/telavatquran/naba.mp3/");
player.prepare();
player.start();
} else if (new File("/storage/extSdCard/").exists()) {
seekUpdation();
player.setDataSource("/storage/extSdCard/telavatquran/naba.mp3/");
player.prepare();
player.start();
} else if (new File("/mnt/extSdCard/").exists()) {
seekUpdation();
player.setDataSource("/mnt/extSdCard/telavatquran/naba.mp3/");
player.prepare();
player.start();
} else if (new File("/mnt/sdcard/external_sd/").exists()) {
seekUpdation();
player.setDataSource("/mnt/sdcard/external_sd/telavatquran/naba.mp3/");
player.prepare();
player.start();
} else if (new File("storage/sdcard1/").exists()) {
seekUpdation();
player.setDataSource("storage/sdcard1/telavatquran/naba.mp3/");
player.prepare();
player.start();
} else if (new File("/mnt/ext_sdcard/").exists()) {
seekUpdation();
player.setDataSource("/mnt/ext_sdcard/telavatquran/naba.mp3/");
player.prepare();
player.start();
}
} catch (Exception e) {
}
I’d appreciate your cooperation.