cover art on android

后端 未结 7 835
-上瘾入骨i
-上瘾入骨i 2020-11-29 19:47

I am developing a sort of media player for android. The question is how can i get the cover art of audio file on android. For example the default android media player shows

7条回答
  •  孤城傲影
    2020-11-29 19:53

    I don't know why everybody is making it so complicated you can use Glide to achieve this in simplest and efficient way with just 1 line of code

    Declare this path in App Constants -

    final public static Uri sArtworkUri = Uri
                    .parse("content://media/external/audio/albumart");
    

    Get Image Uri using Album ID

    Uri uri = ContentUris.withAppendedId(PlayerConstants.sArtworkUri,
                            listOfAlbums.get(position).getAlbumID());
    

    Now simply display album art using uri :-

        Glide.with(context).load(uri).placeholder(R.drawable.art_default).error(R.drawable.art_default)
                        .crossFade().centerCrop().into(holder.albumImage);
    

    Glide will handle caching, scaling and lazy loading of images for you.

    Hope it help somebody.

提交回复
热议问题