List all music in MediaStore with the PATHs

前端 未结 4 1723
刺人心
刺人心 2020-12-02 10:45

Ok so I\'ve been working on this project for a few days now and most of my time has been working out how to list all the music on a device in a LIST VIEW or something else,

4条回答
  •  星月不相逢
    2020-12-02 11:19

    You can list all the music files using this code

    //Some audio may be explicitly marked as not being music
    String selection = MediaStore.Audio.Media.IS_MUSIC + " != 0";
    
    String[] projection = {
            MediaStore.Audio.Media._ID,
            MediaStore.Audio.Media.ARTIST,
            MediaStore.Audio.Media.TITLE,
            MediaStore.Audio.Media.DATA,
            MediaStore.Audio.Media.DISPLAY_NAME,
            MediaStore.Audio.Media.DURATION
    };
    
    cursor = this.managedQuery(
            MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
            projection,
            selection,
            null,
            null);
    
    private List songs = new ArrayList();
    while(cursor.moveToNext()) {
            songs.add(cursor.getString(0) + "||" 
                        + cursor.getString(1) + "||" 
                        + cursor.getString(2) + "||"
                        + cursor.getString(3) + "||"
                        + cursor.getString(4) + "||" 
                        + cursor.getString(5));
    }
    

    I have not tried this code, but it seems correct. You'll be on the right track with that.

提交回复
热议问题