How to access all mp3 files from all the subfolders in the sdcard?

后端 未结 2 1089
Happy的楠姐
Happy的楠姐 2020-12-06 23:33

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 subf

相关标签:
2条回答
  • 2020-12-07 00:02
    File home = new File(MEDIA_PATH);
    

    Then

    walkdir(home);
    

    WalkDir method

    public void walkdir(File dir) {
    String Pattern = ".mp3";
    File listFile[] = dir.listFiles();
    if (listFile != null) {
    for (int i = 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

    0 讨论(0)
  • 2020-12-07 00:10

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

    0 讨论(0)
提交回复
热议问题