Fresco 获取嵌入式封面艺术

Fresco obtaining embedded cover art

Androidfresco 图像加载库提供了多种组件来自定义从多个来源加载图像。在我的情况下,我想检索 audio/mp3 文件的嵌入式封面( 而不是 可以使用 uri 访问的专辑封面)。这可以使用 Android MediaMetadataRetriever or some custom library like FFmpegMediaMetadataRetriever.

来实现

问题是,API 总是需要一个 PATH 和 returns 一个 字节数组 .这使得它很难集成到基于流的壁画管道中。

理想情况下,我想以类似于 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 但不是 Producers 的方式来实现。数据已经在解码器阶段加载。我不知道这应该发生在哪一层以及是否可能。

滑翔代码供参考:

@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();
    }
}

结果将加载到 SimpleDraweeView 中。或者,我愿意接受任何允许我使用 fresco 将嵌入式封面艺术异步加载到 SimpleDraweeView 中的解决方案。

我已经 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 展示了用法。

请注意,这会将当前的最低 SDK 版本从 9 提高到 10。