获取嵌入的mp3文件嵌入艺术失败 [英] Get embedded mp3 file embedded art failed

查看:1851
本文介绍了获取嵌入的mp3文件嵌入艺术失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图得到一个MP3文件的专辑封面。我认为这样做最好,最彻底的方法是使用MediaMetadataRetriever类。但由于某些原因调用getEmbeddedPicture方法不起作用。图像不显示,LogCat中显示了一个错误:

I'm trying to get the album art of a MP3 file. I thought the best and cleanest way to do this is use the MediaMetadataRetriever class. But for some reason calling the getEmbeddedPicture method doesn't work. The image isn't showing, LogCat shows an error:

04-29 18:36:19.520: E/MediaMetadataRetrieverJNI(25661): getEmbeddedPicture: Call to getEmbeddedPicture failed.

这是code,似乎并没有工作:

This is the code that doesn't seem to work:

    @Override
    protected Void doInBackground(Void... params) {
        // TODO Auto-generated method stub
        MediaMetadataRetriever mmdr = new MediaMetadataRetriever();
        mmdr.setDataSource(path); //path of the MP3 file on SD Card
        bites = mmdr.getEmbeddedPicture();
        if(bites != null)
        artBM = BitmapFactory.decodeByteArray(bites, 0, bites.length);
        return null;
    }

我运行它的设备上使用Android 4.2,所以不应该有与MediaMetadataRetriever的任何问题(API需要10级)。我测试的文件显示在Windows资源管理器的形象,所以似乎有艺术嵌入。任何人有什么想法?

I'm running it on a device with Android 4.2, so there shouldn't be any issue with the MediaMetadataRetriever(requires api lvl 10). The files I tested show an image in Windows explorer, so there seems to be art embedded. Anyone have any thoughts on this?

推荐答案

并非所有的MP3文件已专辑封面嵌入式,对某些唱片专辑封面放在相册文件夹里面,所以你可以看到专辑封面的所有文件内该文件夹,

Not all MP3 files have Album art embedded, for some albums the Album art is placed inside the album folder, so you can see album art for all the files inside that folder,

MediaMetadataRetriever mmr = new MediaMetadataRetriever();
mmr.setDataSource(mp3_file_path); 

这会专辑封面如果专辑封面嵌入在文件中,因此,让一个默认的图像作为专辑封面为其未嵌入专辑封面的文件,并检查返回的字节[]为空或不是,

This will get the Album art if the Album art is embedded in that file, So make a default image as album art for files which are not embedded with Album art, and check if the returned byte[] is null or not,

如果字节[]不为空则专辑封面被检索,如果它为null,则设置默认的专辑封面图片

If the byte[] is not null then Album art is retrieved, if it is null then set the default album art image

在我的项目im使用这种

In my Project Im using this

    MediaMetadataRetriever mmr = new MediaMetadataRetriever();
    mmr.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.adele));
    }

我希望这会帮助你。

I hope this will help you

这篇关于获取嵌入的mp3文件嵌入艺术失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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