gpt4 book ai didi

java - 如何在android中从光标处检索图像?获取 ImageView ?

转载 作者:太空宇宙 更新时间:2023-11-04 11:21:01 25 4
gpt4 key购买 nike

我是 Android 开发新手,正在尝试构建一个音乐播放器。为了在 RecyclerView 中添加歌曲数据,我创建了一个 ArrayList (thisList),其中包含歌曲数据(包括专辑封面),但我不知道如何将图像添加到列表中:(

 if(musicCursor!=null && musicCursor.moveToFirst()){
//get columns
int titleColumn = musicCursor.getColumnIndex
(android.provider.MediaStore.Audio.Media.TITLE);
int idColumn = musicCursor.getColumnIndex
(android.provider.MediaStore.Audio.Media._ID);
int artistColumn = musicCursor.getColumnIndex
(android.provider.MediaStore.Audio.Media.ARTIST);
int albumColumn = musicCursor.getColumnIndex
(MediaStore.Audio.Media.ALBUM);

int albumArtColumn = musicCursor.getColumnIndex
(android.provider.MediaStore.Audio.Albums.ALBUM_ART);

//add songs to list
do {
long thisId = musicCursor.getLong(idColumn);
String thisTitle = musicCursor.getString(titleColumn);
String thisArtist = musicCursor.getString(artistColumn);
String thisAlbum = musicCursor.getString(albumColumn);

//ImageView thisAlbumArt = musicCursor. ????

theList.add(newSong(thisId,thisTitle,
thisArtist,thisAlbum,thisAlbumArt));
}
while (musicCursor.moveToNext());
}

最佳答案

试试这个:

Cursor artCursor = context.getContentResolver().query(
MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI,
new String[] {MediaStore.Audio.AlbumColumns.ALBUM_ART},
MediaStore.Audio.Media._ID+" =?",
new String[]{String.valueOf(albumId)},
null);
String albumArt;
if(artCursor.moveToNext()) {
albumArt = "file://"+artCursor.getString(0);
} else {
albumArt = null;
}
artCursor.close();

if(albumArt != null) {
BitmapFactory.decodeFile(new File(albumArt));
}

关于java - 如何在android中从光标处检索图像?获取 ImageView ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44913473/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com