Skip to content Skip to sidebar Skip to footer

Check If Album Art Exists?

I'm building a music player app. I'm trying to populate a recyclerView with album arts of songs. I successfully did that with the code that is given below. But some of the songs do

Solution 1:

The easiest way:

//  loading album cover using Glide library
            String stralbumId = c.getString(c
                    .getColumnIndex(BaseColumns._ID));

            Uri ImageUrl = getAlbumUri(mContext, stralbumId);
            if (ImageUrl != null) {
                Glide.with(mContext)
                        .asBitmap()
                        .load(ImageUrl)
                        .into(image);
            }

and

publicUrigetAlbumUri(Context mContext,String album_id){
if(mContext!=null) {
    Uri sArtworkUri = Uri.parse("content://media/external/audio/albumart");
    Uri imageUri = Uri.withAppendedPath(sArtworkUri, String.valueOf(album_id));
    return imageUri;
}
returnnull;

}

Solution 2:

you can check for album cover by using the MediaMetadataRetriever try the code below and also read the MediaMetadataRetrieverDocumentation

MediaMetadataRetrieverretriver=newMediaMetadataRetriever();
retriver.setDataSource(musicFile.getAbsolutePath());
byte[] cover = retriver.getEmbeddedPicture();
if(cover == null){
  // get cover from the internet 
}else{
  // use glide to load the album art
}

Post a Comment for "Check If Album Art Exists?"