1

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);
    }
zazazas
  • 11
  • 2
  • Which statement gives that exception? And why dont you catch that exception? Or do you? – blackapps Jun 05 '22 at 07:19
  • `cursor.getColumnIndexOrThrow` Where do you catch that exception when it throws? – blackapps Jun 05 '22 at 07:22
  • @blackapps The FileNotFoundException happens at the end of the getAlbumArtwork method according to android studio. I haven't added a default art resource to be used when the file doesn't have album art so I didn't add a catch for it. Will not catching it make it not work for files that have album art? – zazazas Jun 05 '22 at 09:38
  • `cursor.getColumnIndexOrThrow` isn't caught I believe, it didn't give any problems as far as I could tell since all the FileNotFoundExceptions had different IDs that came from the cursor. – zazazas Jun 05 '22 at 09:44

0 Answers0