Most robust way to fetch album art in Android

后端 未结 4 1367
没有蜡笔的小新
没有蜡笔的小新 2020-12-09 23:24

Please note that I have already been through similar questions and their answers here and on other websites. I also have a solution that works on some devices (my G2X runnin

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-09 23:56

    This below code snippet returns the uri for the album art cache present in the MediaStore. may be this will help.

                Cursor cursorAudio = managedQuery(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, {MediaStore.Audio.Media.ALBUM_ID, MediaStore.Audio.Media.DATA}, MediaStore.Audio.Media.DATA+ " LIKE \"" + path+ "\"", null, null);if(cursorAudio != null  && cursorAudio.moveToFirst()){
            Long albumId = Long.valueOf(cursorAudio.getString(cursorAudio.getColumnIndex(MediaStore.Audio.Media.ALBUM_ID)));
            cursorAudio.close();
            Cursor cursorAlbum = managedQuery(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, {MediaStore.Audio.Albums._ID, MediaStore.Audio.Albums.ALBUM_ART}, MediaStore.Audio.Albums._ID+ "=" + albumId, null, null);
            if(cursorAlbum != null  && cursorAlbum.moveToFirst()){
                String uri = cursorAlbum.getString(cursorAlbum.getColumnIndex(MediaStore.Audio.Albums.ALBUM_ART));
                cursorAlbum.close();
                if(uri != null){
                    return Uri.parse(uri);
                }
            }
    

提交回复
热议问题