0

The Android fresco image loading library provides a variety of components to customize image loading from several sources. In my situation, I want to retrieve the embedded cover art of an audio/mp3 file (not the album art which can be accessed using an uri). This can be achieved using the Android MediaMetadataRetriever or some custom library like FFmpegMediaMetadataRetriever.

The problem is, that the API always requires a PATH and returns an array of bytes. This makes it hard integrate into the stream-based fresco pipeline.

Ideally, I would like to implement this similar to how Glide allows it. Aka some very low-level function which obtains the bytes and simply wraps them in a stream. Afaik, we can use custom Decoders, but not Producers. The data has already been loaded at Decoder stage. I have no idea at which layer this should happen and if it's possible.

Glide code for reference:

@Override public InputStream loadData(Priority priority) throws Exception {
    MediaMetadataRetriever retriever = new MediaMetadataRetriever();
    try {
        retriever.setDataSource(model.path);
        byte[] picture = retriever.getEmbeddedPicture();
        if (picture != null) {
            return new ByteArrayInputStream(picture);
        } else {
            return fallback(model.path);
        }
    } finally {
        retriever.release();
    }
}

The result will be loaded into a SimpleDraweeView. Alternatively, I'm open to any solution which will allow me to asynchronously load embedded cover art into a SimpleDraweeView using fresco.

1 Answers1

0

I've forked fresco and added my own Producer which is able to extract the embedded pictures of audio files similar to the Glide solution in the provided snippet. This LocalAudioThumbnailProducer applies to content with the audio/ MimeType. I've also written a small sample app to showcase the usage.

Please note that this raises the current minimum SDK version from 9 to 10.