简体   繁体   English

我的代码只从内部存储中获取 mp3 文件,而不是从 SD 卡中获取

[英]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.我为我的音乐播放器编写了这段代码,以从存储中获取所有“.mp3”文件,但它不会从 SD 卡中获取。 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") && // ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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