Skip to content Skip to sidebar Skip to footer

How To Access All Mp3 Files From All The Subfolders In The Sdcard?

I'm trying to make an mp3 player app, and when I run it from my phone it only reads MP3's that are present on the SD card itself. It does not read any MP3's from the subfolders tha

Solution 1:

There is the MusicRetriever example in the Android SDK. It uses a ContentResolver.

Solution 2:

Filehome=newFile(MEDIA_PATH);

Then

walkdir(home);

WalkDir method

publicvoidwalkdir(File dir) {
StringPattern=".mp3";
File listFile[] = dir.listFiles();
if (listFile != null) {
for (inti=0; i < listFile.length; i++) {
if (listFile[i].isDirectory()) {
walkdir(listFile[i]);
} else {
if (listFile[i].getName().endsWith(Pattern)){
  //Do what ever u want// add the path to hash map    
}
}
}  
}  
}

Even better use enhanced for loop as suggested by blackbelt @

Delete only .jpg files from folder in android

Instead of deleting add the path to the hahsmap

Post a Comment for "How To Access All Mp3 Files From All The Subfolders In The Sdcard?"