我正在尝试在回收者视图中获取音乐的专辑封面。我正在使用Kotlin,但我是新手。我能够获取音乐文件并将其显示在“回收者”视图中,但是我无法获取专辑封面并在每个音乐文件的imageview中显示它。我使用以下代码获取带有艺术家姓名,时长和标题的音乐文件:
fun initMusic()
{
var cursor : Cursor? = contentResolver.query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, null,
null, null, MediaStore.Audio.Media.TITLE + " ASC")
if(cursor!!.moveToFirst())
{
do {
var title = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.TITLE))
var album = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ALBUM))
var duration = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.DURATION))
var artist = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ARTIST))
var path = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.DATA))
(musicList as ArrayList<Music>).add(Music(title, album, artist, duration, "ic_launcher_background", path))
} while (cursor.moveToNext())
}
}
我需要帮助才能将专辑封面显示在图像视图中。