Get cover picture by song

后端 未结 1 651
我在风中等你
我在风中等你 2020-12-03 16:12

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

相关标签:
1条回答
  • 2020-12-03 16:51

    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.
    
    0 讨论(0)
提交回复
热议问题