Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MediaMetadataRetrieverJNI: getEmbeddedPicture failed

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

like image 936
Paul Woitaschek Avatar asked Aug 18 '14 15:08

Paul Woitaschek


1 Answers

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

like image 91
Akshay Mukadam Avatar answered Nov 04 '22 01:11

Akshay Mukadam