I've seen a lot of people ask questions related to this, but they were all written in Java and they all use the method getContentResolver().loadThumbnail(imageUri, thumbSize, null);
, but how to use loadThumbnail()
in Kotlin?
Here is my attempt:
while (cursor.moveToNext()) {
val id = cursor.getLong(idColumn)
val displayName = cursor.getString(displayNameColumn)
val album = cursor.getString(albumColumn)
val albumId = cursor.getLong(albumIdColumn)
val duration = cursor.getString(durationColumn)
val contentUri = ContentUris.withAppendedId(
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, id
)
val albumUri = ContentUris.withAppendedId(
MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, albumId
)
val albumCover = ContentResolver().loadThumbnail(
albumUri,
Size(100, 100),
null
)
val song = Song(id, displayName, album, albumId, duration, contentUri, albumUri,
albumCover.asImageBitmap())
songs += song
Log.v(TAG, "Added song:${song.displayName}")
}
Then Android studio prompted me with an error about ContentResolver():
Cannot create an instance of an abstract class
So how do I use loadThumbnail()
appropriately?
Thank you!