Android songs fetching from SD card

后端 未结 5 660
执念已碎
执念已碎 2020-12-06 03:37

I am fetching my songs from the SD card and putting him to the list view.

I am using this method. but its taking some time and if path is different I didn\'t get tha

5条回答
  •  醉梦人生
    2020-12-06 04:32

    //try this its working code

    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;
    }
    

提交回复
热议问题