获取封面图片由曲 [英] Get cover picture by song
问题描述
是否有可能获得通过歌曲封面图片,而不是由唱片。 因为我有一个自结合专辑的歌曲,他们都有不同的封面图片。 但是,当我想查询他们,我总是得到相同的图片返回。
Is it possible to get a cover picture by song and not by album. Because I have one self combined album with songs and they all have different cover pictures. But when I want to query them I always get the same picture returned.
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));
所以我想知道它是如何可能得到的歌曲的封面图片。
So i would like to know how it's possible to get an cover image of an song.
我知道MusicUtils支持getArtwork由SongId,但我应该用什么ID,因为MediaStore.Audio.Media._ID是行不通的。
I know MusicUtils supports getArtwork by SongId, but what ID should I use because MediaStore.Audio.Media._ID is not working.
推荐答案
我不熟悉的 MusicUtils
,但是,你应该能够从中获取的封面文件本身使用类MediaMetadataRetriever
。下面是一个简单的code片断展示了如何使用它。引用的URI是内容的URI要检索技术的文件。
I'm not familiar with MusicUtils
, however, you should be able to get the cover art from the file itself by using MediaMetadataRetriever
. Here is a brief code snippet showing how to use it. The uri referenced is the content uri for the file you want to retrieve the art for.
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.
这篇关于获取封面图片由曲的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!