I've been trying to follow Android loadThumbnail Album Artwork (API 29), but I always get the same error that the OP had in that thread, even when using the fixed code given in the answer. Songs can play normally, it's just the album art that gives
java.io.FileNotFoundException: No media for album content://media/external/audio/albums/*number*
This is my current code, if I use MediaStore.Audio.Media.ALBUM_ID instead of MediaStore.Audio.Albums._ID, the app crashes entirely. Anyone know where I went wrong?
String[] projection = {
MediaStore.Audio.Media.TITLE,
MediaStore.Audio.Media.DATA,
MediaStore.Audio.Media.DURATION,
MediaStore.Audio.Albums._ID
};
Cursor cursor = getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
projection, null, null, null);
while (cursor.moveToNext()) {
long id = cursor.getLong(cursor.getColumnIndexOrThrow(MediaStore.Audio.Albums._ID));
Bitmap albumArt = null;
try {
albumArt = getAlbumArtwork(getContentResolver(), id);
} catch (IOException e) {
e.printStackTrace();
}
private Bitmap getAlbumArtwork(ContentResolver resolver, long albumId) throws IOException {
Uri contentUri = ContentUris.withAppendedId(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, albumId);
return resolver.loadThumbnail(contentUri, new Size(300, 300), null);
}