Im using android and am iterating over a few hundred mediafiles to find the first embedded picture, which works well, but sends me a lot of errors in my logcat.
Im using this code:
for (String s : ArrayList <String> paths){
    MediaMetadataRetriever mmr = new MediaMetadataRetriever();
    mmr.setDataSource(path);
    byte[] data = mmr.getEmbeddedPicture();
    if (data != null) {
    ...
}
the error it logs is:
E/MediaMetadataRetrieverJNI﹕ getEmbeddedPicture: Call to getEmbeddedPicture failed.
E/MediaMetadataRetrieverJNI﹕ getEmbeddedPicture: Call to getEmbeddedPicture failed.
E/MediaMetadataRetrieverJNI﹕ getEmbeddedPicture: Call to getEmbeddedPicture failed.
E/MediaMetadataRetrieverJNI﹕ getEmbeddedPicture: Call to getEmbeddedPicture failed.
E/MediaMetadataRetrieverJNI﹕ getEmbeddedPicture: Call to getEmbeddedPicture failed.
E/MediaMetadataRetrieverJNI﹕ getEmbeddedPicture: Call to getEmbeddedPicture failed.
.....
Am i using it right? If so can I suppress the error, it makes debugging annoying.
According to MediaMetadataRetriever it should simply return null
Using getEmbeddedPicture will not be enough You need to add a little bit code for that.
Try this
md.setDataSource(songsList.get(index).get("songPath"));
byte[] artBytes =  mmr.getEmbeddedPicture();
if(artBytes != null)
{
    InputStream is = new ByteArrayInputStream(mmr.getEmbeddedPicture());
    Bitmap bm = BitmapFactory.decodeStream(is);
    imgArt.setImageBitmap(bm);
}
else
{
    imgArt.setImageDrawable(getResources().getDrawable(R.drawable.your_default_image));
}
Also look at this:
try {
        byte [] art = md.getEmbeddedPicture();
        Bitmap songImage = BitmapFactory
            .decodeByteArray(art, 0, art.length);
        md.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM));
        String artist =md.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST));
        String genre = md.extractMetadata(MediaMetadataRetriever.METADATA_KEY_GENRE));
    } catch (Exception e) {
         // TO-DO Exception
    }
Refer the docs
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