cover art on android

后端 未结 7 809
-上瘾入骨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.

    0 讨论(0)
  • 2020-11-29 19:53

    Based on your comments to others, it seems like your question is less about Android and more about how to get album art in general. Perhaps this article on retrieving album art from Amazon will be helpful. Once you have a local copy and store it as Nick has suggested, I believe you should be able to retrieve it the way Fudgey suggested.

    0 讨论(0)
  • 2020-11-29 19:54

    Here i can attach one function that is return album art from media store .

    Here in function we just have to pass the album_id which we get from Media store .

    public Bitmap getAlbumart(Long album_id) 
       {
            Bitmap bm = null;
            try 
            {
                final Uri sArtworkUri = Uri
                    .parse("content://media/external/audio/albumart");
    
                Uri uri = ContentUris.withAppendedId(sArtworkUri, album_id);
    
                ParcelFileDescriptor pfd = context.getContentResolver()
                    .openFileDescriptor(uri, "r");
    
                if (pfd != null) 
                {
                    FileDescriptor fd = pfd.getFileDescriptor();
                    bm = BitmapFactory.decodeFileDescriptor(fd);
                }
        } catch (Exception e) {
        }
        return bm;
    }
    
    0 讨论(0)
  • 2020-11-29 20:01
    Uri sArtworkUri = Uri.parse("content://media/external/audio/albumart");
    Uri uri = ContentUris.withAppendedId(sArtworkUri, album_id);
    ContentResolver res = context.getContentResolver();
    InputStream in = res.openInputStream(uri);
    Bitmap artwork = BitmapFactory.decodeStream(in);
    

    More complete sample code can be found in Android Music player source here https://github.com/android/platform_packages_apps_music/blob/master/src/com/android/music/MusicUtils.java method getArtworkQuick.

    0 讨论(0)
  • 2020-11-29 20:04

    You can use

    MediaMetadataRetriever

    class and get track info i.e. Title,Artist,Album,Image

    Bitmap GetImage(String filepath)              //filepath is path of music file
    {
     Bitmap image;
    
    MediaMetadataRetriever mData=new MediaMetadataRetriever();
    mData.setDataSource(filePath);
         try{
                byte art[]=mData.getEmbeddedPicture();
                image=BitmapFactory.decodeByteArray(art, 0, art.length);
            }
        catch(Exception e)
            { 
               image=null;
            }
        return image;
    }
    
    0 讨论(0)
  • 2020-11-29 20:09

    I don't know if you read that google is making Stackoverflow the official Android app development Q&A medium but for beginner questions... Now, I know nothing about developing in andriod, but a quick search of the Android Developers site, I found this:

    MediaStore.Audio.AlbumColumns

    Hopefully it'll help.

    0 讨论(0)
提交回复
热议问题