按歌曲获取封面图片

Mar*_*aar 2 android mediastore media-player

是否可以通过歌曲而不是专辑获得封面图片.因为我有一张带歌曲的自组合专辑,而且他们都有不同的封面图片.但是当我想查询它们时,我总是得到相同的图片.

String[] ARG_STRING = {MediaStore.Audio.Media.ALBUM_ID};
...
String albumCover = _cursor.getString(_cursor.getColumnIndex(MediaStore.Audio.Media.ALBUM_ID));
...
MusicUtils.getArtwork(this, -1, Integer.parseInt(albumID));
Run Code Online (Sandbox Code Playgroud)

所以我想知道如何获得一首歌的封面图片.

我知道MusicUtils支持SongId的getArtwork,但我应该使用什么ID,因为MediaStore.Audio.Media._ID不起作用.

phx*_*wke 13

MusicUtils但是,我不熟悉,你应该能够通过使用从文件本身获得封面MediaMetadataRetriever.这是一个简短的代码片段,展示了如何使用它.引用的uri是您要为其检索艺术的文件的内容uri.

MediaMetadataRetriever mmr = new MediaMetadataRetriever();
byte[] rawArt;
Bitmap art;
BitmapFactory.Options bfo=new BitmapFactory.Options();

mmr.setDataSource(getApplicationContext(), uri);
rawArt = mmr.getEmbeddedPicture();

// if rawArt is null then no cover art is embedded in the file or is not 
// recognized as such.
if (null != rawArt) 
    art = BitmapFactory.decodeByteArray(rawArt, 0, rawArt.length, bfo);

// Code that uses the cover art retrieved below.
Run Code Online (Sandbox Code Playgroud)