简体   繁体   中英

How can I get a list of all mp3 files on the sd card regardless of directory in android?

Using code from open source MusicDroid with the following code that I found during a search for this problem, I can only get mp3 files that are in the root directory /sdcard/

File home = Environment.getExternalStorageDirectory();

if (home.listFiles( new Mp3Filter()).length > 0) {
    for (File file : home.listFiles( new Mp3Filter())) {
        songs.add(file.getAbsolutePath());
    }
    ArrayAdapter<String> songList = new ArrayAdapter<String>
          (this,R.layout.song_item,songs);
    setListAdapter(songList);
}

How can I get all the mp3 files from the card (in any directory) into my 'songs' list?

Depending on what you want, you could just query the media store. Android scans the sdcard every time it is remounted, so MediaStore.Audio should have all the information you need.

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