如何将MediaMetadataRetriever SetDataSource用于外部存储中的文件 [英] How to use MediaMetadataRetriever SetDataSource for file in external storage

查看:1975
本文介绍了如何将MediaMetadataRetriever SetDataSource用于外部存储中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从MP3文件中提取专辑封面但是我无法给出合适的歌曲位置,我可以将其提供给SetDataSource方法。我尝试了一切,但它仍然给我错误 IllegalArgumentException

I'm trying to extract Album art from MP3 file But I not able to give proper location of song, which I can give it to SetDataSource method. I tried everything but still it gives me error IllegalArgumentException.

这一行都发生在这行 metaRetriver.setDataSource(MainActivity.this,Uri.parse(/ sdcard / song.mp3)); 被执行

It all happens when this line metaRetriver.setDataSource(MainActivity.this, Uri.parse("/sdcard/song.mp3")); gets executed

我的代码。

public class MainActivity extends AppCompatActivity {

MediaMetadataRetriever metaRetriver;
byte[] art;
ImageView album_art;

Bitmap songImage;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    getInit();

    metaRetriver = new MediaMetadataRetriever();
    metaRetriver.setDataSource(MainActivity.this, Uri.parse("/sdcard/song.mp3"));


    art = metaRetriver.getEmbeddedPicture();

    if (art != null) {
        songImage = BitmapFactory
                .decodeByteArray(art, 0, art.length);
        album_art.setImageBitmap(songImage);
    } else {
        String error = "art is null";
        Log.i("lolol", error);
    }

}

public void getInit() {

    album_art = (ImageView) findViewById(R.id.album_art);

}
}

任何人都可以解决这个问题。

Can anyone solve this problem.

推荐答案

来自 Android文档


如果Uri无效,则抛出IllegalArgumentException

Throws IllegalArgumentException if the Uri is invalid

仔细检查song.mp3文件是否在正确的位置,并且应用程序有权查看它。

Double check that the song.mp3 file is in the right place, and the app has permission to see it.

这篇关于如何将MediaMetadataRetriever SetDataSource用于外部存储中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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