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 suggestion on the documentation page I should now be using the loadThumbnail method, which I have been attempting to do. Unfortunately I cannot get the loadThumbnail function to load album artwork, I've only seen it work with images from "MediaStore.Images.Media.EXTERNAL_CONTENT_URI", which does not seem to contain all the albums, nor a method for mapping to them using an ID.
This is my current attempt, which does not seem to be working yet. Has anyone had any success loading album artwork using the new loadThumbnail method? I'm using a Google Pixel 3a for my testing.
Getting the cursor:
return mContext.getContentResolver().query(
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
{
MediaStore.Audio.Media._ID, MediaStore.Audio.Media.TRACK,
MediaStore.Audio.Media.ARTIST, MediaStore.Audio.Media.TITLE, MediaStore.Audio.Media.ALBUM,
MediaStore.Audio.Media.DURATION, MediaStore.Audio.Media.DATA, MediaStore.Audio.Media.YEAR,
MediaStore.Audio.Media.COMPOSER, MediaStore.Audio.Albums.ALBUM_ID
},
MediaStore.Audio.Media._ID + "=?",
new String[]{String.valueOf(id)},
null);
Extracting the album id:
cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Audio.Albums.ALBUM_ID)),
Building the uri to load the thumbnail:
Uri contentUri = ContentUris.withAppendedId(
MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI,
// MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
albumId
);
return resolver.loadThumbnail(contentUri, new Size(640, 480), null);
The error provided:
java.io.FileNotFoundException: No media for album content://media/external/audio/albums/1145137507