如何从url获取歌曲的专辑封面 [英] how can get album art of song from url

查看:591
本文介绍了如何从url获取歌曲的专辑封面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想从url获得歌曲的专辑封面,这是我到目前为止的尝试:

want get album art of song from url and this is my try so far :

SongPath = "www.asd.com/music.mp3";
        android.media.MediaMetadataRetriever mmr = new MediaMetadataRetriever();
    try{
                mmr.setDataSource(SongPath);
        }catch(Exception e){}
                byte [] data = mmr.getEmbeddedPicture();

                if(data != null)
                {
                    Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
                    imageView.setImageBitmap(bitmap);
                }
                else
                {
                    imageView.setImageResource(R.drawable.jak);
                }

但是运行此代码时,请获取以下内容:call to get embedded picture failed 所以我对此进行了研究,有人通过更改此部分来解决该问题
mmr.setDataSource(SongPath);

but when run this code get this : call to get embedded picture failed so i research about this and some people fix that with change this part
mmr.setDataSource(SongPath);

对此

mmr.setDataSource(SongPath,new HashMap<String, String>()); 我这样做,但是在运行应用程序图像视图时什么也不显示并得到:SkImageDecoder::Factory returned null

mmr.setDataSource(SongPath,new HashMap<String, String>()); i do that but when run app image view show nothing and get this : SkImageDecoder::Factory returned null

注意: 我可以做到的唯一方法是使用FFmpegMediaMetadataRetriever库(类似于MediaMetadataRetriever)并工作,但是问题是库似乎很慢..它平均需要4.5秒的时间来获取图片,并在添加此库时从1.8mb中获取apk文件变成24mb!这是如此巨大!

Note : the only way i could do that use FFmpegMediaMetadataRetriever library (its like MediaMetadataRetriever) and worked but problem is library seems slow .. its mean 4,5sec time need to fetch pic and when add this library the apk file from 1.8mb become to 24mb! and this is so huge!

那么世界上任何人都知道如何以一种好的方式做到这一点?如果有人可以帮助

so any one in the world know how can do that with good way ? if any one can please help

推荐答案

您可以按照与File相同的方式使用Glide:从http加载视频缩略图是个坏主意).如果仍然要这样做,请在负载上拍一个.diskCacheStrategy(SOURCE)首先保存文件,然后编写一个自定义解码器以使用

You can use Glide in a similar way you would use it for a File: bumptech/glide#699 if you can figure out how to do it remotely. The problem is that you still need to download the whole .mp3 file, which takes that 4-5 seconds I guess. I'm not exactly sure about the .mp3 format, but I think the album art may be at the end of the file. For this reason this approach is not suggested (similar to how it's a bad idea to load video thumbs from http). If you want to go this way anyway, then slap a .diskCacheStrategy(SOURCE) on the load to save the file first, and then write a custom decoder to use

最好的方法是,如果托管mp3,则从单独的文件中提供专辑封面;或使用公共服务来检索它.查看任何专辑封面下载程序以获取可能的服务.

The best approach is to have the album art served from a separate file if you host the mp3; or use a public service to retrieve it. See any album art downloader program for possible services.

可以肯定的是:如果没有协议,将无法正常工作,并在必要时为www.加上http://https://前缀.

One thing's for sure: without a protocol, nothing will work, prefix your www. with http:// or https:// as necessary.

这篇关于如何从url获取歌曲的专辑封面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆