how to get all all audio files from sd card android

后端 未结 4 1491
清酒与你
清酒与你 2020-12-30 16:35

I want to write a class which gets all the mp3 files from the whole sd card. But actually it only gets the audio files laying directly on the sd card. so it doesnt search tr

4条回答
  •  一生所求
    2020-12-30 17:12

    This code will give you an arrayList of hash map which content the song title as well as song absolute path

    public ArrayList> getAudioList() {
    
        ArrayList> mSongsList = new ArrayList>();
        Cursor mCursor = getContentResolver().query(
                MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
                new String[] { MediaStore.Audio.Media.DISPLAY_NAME,
                        MediaStore.Audio.Media.DATA }, null, null, null);
    
        int count = mCursor.getCount();
        System.out.println("total no of songs are=" + count);
        HashMap songMap;
        while (mCursor.moveToNext()) {
            songMap = new HashMap();
            songMap.put("songTitle",mCursor.getString(mCursor
                            .getColumnIndexOrThrow(MediaStore.Audio.Media.DISPLAY_NAME)));
            songMap.put("songPath", mCursor.getString(mCursor
                    .getColumnIndexOrThrow(MediaStore.Audio.Media.DATA)));
            mSongsList.add(songMap);
        }
        mCursor.close();
        return mSongsList;
    }
    

提交回复
热议问题