4

是否可以按歌曲而不是专辑获得封面图片。因为我有一张自组合的歌曲专辑,而且它们都有不同的封面图片。但是当我想查询它们时,我总是会返回相同的图片。

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));

所以我想知道如何获得歌曲的封面图片。

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

4

1 回答 1

15

我不熟悉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.
于 2013-06-06T21:00:56.630 回答