Hello Everyone , In my media player i need to display the album cover(i dont know how it pronounced actually..I hope right) of the song. I knew for that i have to extract the image from the song itself but how? m wondering. So any help, if possible with some sorts of code. Thanks.
Asked
Active
Viewed 2.4k times
7
-
Duplicate of http://stackoverflow.com/questions/1954434/cover-art-on-android – Rajesh Apr 18 '12 at 12:46
4 Answers
22
for api 10 and above
android.media.MediaMetadataRetriever mmr = new MediaMetadataRetriever();
mmr.setDataSource(songsList.get(songIndex).get("songPath"));
byte [] data = mmr.getEmbeddedPicture();
//coverart is an Imageview object
// convert the byte array to a bitmap
if(data != null)
{
Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
coverart.setImageBitmap(bitmap); //associated cover art in bitmap
}
else
{
coverart.setImageResource(R.drawable.fallback_cover); //any default cover resourse folder
}
coverart.setAdjustViewBounds(true);
coverart.setLayoutParams(new LinearLayout.LayoutParams(500, 500));

atschpe
- 121
- 14

Nikhil Goswami
- 75
- 2
- 13
4
Try FFmpegMediaMetadataRetriever:
FFmpegMediaMetadataRetriever retriever = new FFmpegMediaMetadataRetriever();
retriever.setDataSource(uri);
byte [] data = retriever.getEmbeddedPicture();
// convert the byte array to a bitmap
Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
// do something with the image ...
// mImageView.setImageBitmap(bitmap);
retriever.release();

William Seemann
- 3,440
- 10
- 44
- 78
2
You can try with Picasso by using album_id. it is open source & less memory cache.
Dependency:
implementation 'com.squareup.picasso:picasso:2.71828'
Code:
String albumId = songObject.getAlbum_id();
final Uri albumUri = Uri.parse("content://media/external/audio/albumart");
Uri uri = ContentUris.withAppendedId(albumUri, Long.parseLong(albumId));
Picasso.get().load(uri)
.fit()
.centerCrop()
.error(R.drawable.img_album)
.into(holder.imgAlbumSongObject);
This is very late. but, may help someone.

Silambarasan
- 645
- 1
- 7
- 13
-2
MediaMetadataRetriever mmr = new MediaMetadataRetriever();
mmr.setDataSource(filePath);
String albumName = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM));
Note this will work only at api level 10 or above

Nikhil Goswami
- 75
- 2
- 13

Nikesh Devaki
- 2,091
- 2
- 16
- 24
-
2you should comment the code better, at least type in `Try this:`, better place a link to MediaMetaDataRetriever reference... – nio Nov 24 '13 at 11:48
-
this does not answer the question of how to extract album artwork (image) – Vladyslav Matviienko Nov 30 '17 at 09:46
-