Skip to content Skip to sidebar Skip to footer

Android Loadthumbnail Album Artwork (api 29)

I've been attempting to resolve an album artwork issue for a while but with no success as of yet. Since API 29 the Album Artwork MediaStore field was deprecated (docs). As per the

Solution 1:

Looks like I've found a solution that works:

Cursor:

Cursorimages= resolver.query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
                    newString[]{MediaStore.Audio.Media.ALBUM_ID},
                    null, null, null);

Column:

longid = images.getLong(images.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM_ID));

For getting the bitmap:

@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)private Bitmap getAlbumArtwork(ContentResolver resolver, long albumId)throws IOException {
    UricontentUri= ContentUris.withAppendedId(
            MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI,
            albumId
    );

    return resolver.loadThumbnail(contentUri, newSize(640, 480), null);
}

Solution 2:

Get Andriod Studio latest 4.2.x and targetSdkVersion to 30

Uriuri= MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
    String[] projection = {MediaStore.Audio.AudioColumns.DATA,
            MediaStore.Audio.AudioColumns.TITLE ,
            MediaStore.Audio.AudioColumns.ALBUM,
            MediaStore.Audio.ArtistColumns.ARTIST,
            MediaStore.Audio.AudioColumns.ALBUM_ID};
    Cursorc= getContentResolver().query(uri, projection, null, null, null);

    if (c != null) {
        while (c.moveToNext()) {
            SongTracksongTracks=newSongTrack();
            MediaItemmediaItem=newMediaItem();
            Stringpath= c.getString(0);   // Retrieve path.Stringname= c.getString(1);   // Retrieve name.Stringalbum= c.getString(2);  // Retrieve album name.Stringartist= c.getString(3); // Retrieve artist name.
            Long albumID=c.getLong(4);

            songTracks.setSongTitle(name);
            songTracks.setSongFilePath(path);
            songTracks.setAlbumartPath("content://media/external/audio/albumart/"+albumID.toString());
            songTracks.setArtist(artist);
            songTracks.setAlbumName(album); 
  Glide.with(getContext()).load(imgFilePath).placeholder(R.drawable.missed).into(tracksAlbumArt);

Post a Comment for "Android Loadthumbnail Album Artwork (api 29)"