Since you want your users to select just a directory, you will need to find the mp3 files yourself.
You can recursively traverse a directory looking for files that end in ".mp3".
public static void findMp3s(File root, List<File> toBuildUp) {
// if the File is not a directory, and the name ends with mp3
// we will add it to our list of mp3s
if (!root.isDirectory() && root.getName().endsWith("mp3")) {
toBuildUp.add(root);
return;
}
if (!file.isDirectory())
return;
// Now, we know that root is a Directory
// We will look through every file and directory under root,
// and recursively look for more mp3 files
for (File f: root.listFiles()){
findMp3s(f, toBuildUp);
}
}
The preceding method will recursively traverse all directories and populate toBuildUp
with every mp3 file under that directory.
You will call this method like:
List<File> allMp3s = new ArrayList<File>();
findAllMp3s(selectedDirectory, allMp3s);