【问题标题】:Get cover picture by song按歌曲获取封面图片
【发布时间】:2013-03-09 18:58:21
【问题描述】:

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

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 不起作用。

【问题讨论】:

    标签: android media-player mediastore


    【解决方案1】:

    我不熟悉MusicUtils,但是,您应该可以使用MediaMetadataRetriever 从文件本身获取封面。这是一个简短的代码 sn-p 显示如何使用它。引用的 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.
    

    【讨论】:

    • @MartinMetselaar 你在哪里得到图像 uri 一首歌..??如何获取图像 uri 一首歌..?
    • 我猜可能 URI 是按照这个问题中引用的方式构建的:stackoverflow.com/q/3438809/997940
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多