在 android 11 中收到专辑封面
Receiving album art in android 11
As known, ALBUM_ART was deprecated in Android 11. Google says that ContentResolver.loadThumbnail 应该改用。但我完全不明白如何使用它,尤其是我应该提供的第一个参数 uri。文档说:
Uri: The item that should be visualized as a thumbnail. This value cannot be null.
那个物品是什么,我怎样才能得到它?这是音乐文件的Uri吗?
您需要传入曲目的Uri
//This will get you the uri of the track, if you already have the track id
Uri trackUri = ContentUris.withAppendedId(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, trackId);
Bitmap bm = contentResolver.loadThumbnail(trackUri, new Size(512,512), null);
将位图设置为 ImageView
imageView.setImageBitmap(bm);
As known, ALBUM_ART was deprecated in Android 11. Google says that ContentResolver.loadThumbnail 应该改用。但我完全不明白如何使用它,尤其是我应该提供的第一个参数 uri。文档说:
Uri: The item that should be visualized as a thumbnail. This value cannot be null.
那个物品是什么,我怎样才能得到它?这是音乐文件的Uri吗?
您需要传入曲目的Uri
//This will get you the uri of the track, if you already have the track id
Uri trackUri = ContentUris.withAppendedId(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, trackId);
Bitmap bm = contentResolver.loadThumbnail(trackUri, new Size(512,512), null);
将位图设置为 ImageView
imageView.setImageBitmap(bm);