简体   繁体   中英

My code only fetches mp3 files from internal storage and not from SD card

public ArrayList<File> fetchSongs(File file){
        ArrayList arrayList = new ArrayList();
        File[] songs = file.listFiles();
        if (songs != null){
            for (File myFile: songs){
                if (myFile.isDirectory() && !myFile.isHidden()){
                    arrayList.addAll(fetchSongs(myFile));
                }else{
                    if (myFile.getName().endsWith(".mp3") && !myFile.getName().startsWith(".")){
                        arrayList.add(myFile);
                    }
                }
            }
        }
        return arrayList;
    }

I wrote this code for my music player to fetch all ".mp3" files from the storage but it doesn't fetch from SD card. Though it works fine with internal storage. Your help will be much appreciated. Thankyou

Double check that you aren't being affected by mixed case names, try changing the test to lowercase name:

if (myFile.getName().toLowerCase().endsWith(".mp3") && // ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM