问题描述
我正在尝试从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.
推荐答案
来自:
仔细检查song.mp3文件是否在正确的位置,并且应用程序有权查看它。
Double check that the song.mp3 file is in the right place, and the app has permission to see it.
这篇关于如何将MediaMetadataRetriever SetDataSource用于外部存储中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!