7

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

twenk11k
  • 557
  • 5
  • 17
Paul Woitaschek
  • 6,717
  • 5
  • 33
  • 52

1 Answers1

0

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

Akshay Mukadam
  • 2,388
  • 1
  • 27
  • 40
  • I am using the code, but the catch block is not working. – Tushar Monirul Jan 14 '15 at 14:40
  • How is this different than OP's code? He has a problem because he receives `null` and doesn't know why. – TWiStErRob Oct 20 '15 at 14:53
  • 1
    OP knows that getEmbeddedPicture returns null if the file has no embedded picture. That is routine. OP wants to suppress the accompanying log output because it is annoying and OP has done nothing wrong. – w0mbat Apr 11 '23 at 20:26
  • 1
    You would think that you could pre-check for an embedded image like this: retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_HAS_IMAGE) but that actually doesn't work, it's not for looking for embedded images. – w0mbat Apr 11 '23 at 21:19