I'm developing a music player on android and i get a bug that i dont know why. I think I do right but it does not work.
I did search a lot of MediaMetadataRetriever, but I still don't see what my problem is.
I use MediaMetadataRetriever to get infomation about my song. Everything work fine but getEmbeddedPicture(). I get this message whenever getEmbeddedPicture called: 11-15 13:36:11.101: E/MediaMetadataRetrieverJNI(460): getEmbeddedPicture: Call to getEmbeddedPicture failed.
I know this method only called after setDataSource called, and I did it, but I still get that bug ( of course, my song has image in it and I'm using android 2.3.3).
This is the code:
mediaInfo.setDataSource(filePath);//filePath is correct.
byte[] img = mediaInfo.getEmbeddedPicture();//cause error
if (img != null)
imgAlbum.setImageBitmap(BitmapFactory.decodeByteArray(img, 0,img.length));
Thanks.
The following should work:
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.setDataSource(filePath);
byte[] art = retriever.getEmbeddedPicture();
if( art != null ){
imgAlbum.setImageBitmap( BitmapFactory.decodeByteArray(art, 0, art.length));
}
else{
imgAlbum.setImageResource(R.drawable.no_image);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With