Most robust way to fetch album art in Android

后端 未结 4 1374
没有蜡笔的小新
没有蜡笔的小新 2020-12-09 23:24

Please note that I have already been through similar questions and their answers here and on other websites. I also have a solution that works on some devices (my G2X runnin

4条回答
  •  鱼传尺愫
    2020-12-10 00:21

    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;
    }
    

提交回复
热议问题