使用毕加索显示音乐的专辑封面 [英] displaying album art for music using picasso
本文介绍了使用毕加索显示音乐的专辑封面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,我需要使用 Picasso 有效地显示音乐文件的相册艺术.我已经在我的应用程序中配置了毕加索.但是我无法从内部存储中显示音乐文件的专辑封面.
Hello I need to display album art for music files efficiently using Picasso. I already configured picasso in my app. But I am not able to display album art from internal storage for music files.
我尝试了这段代码,但是它不起作用意味着没有错误,但是它什么也没显示.
I tried this code but it's not working means no error but it doesn't display anything.
-
使用uri:
Using uri :
cursor = getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, null, MediaStore.Audio.AudioColumns.DURATION + ">0", null, sortOrder);
cursor.moveToFirst();
a = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ALBUM_ID));
l = Long.parseLong(a);
final Uri sArtworkUri = Uri.parse("content://media/external/audio/albumart");
Uri uri = ContentUris.withAppendedId(sArtworkUri, l);
Picasso.with(MainActivity.this).load(uri).into(iv);
使用新文件:
Using new File :
cursor = getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, null, MediaStore.Audio.AudioColumns.DURATION + ">0", null, sortOrder);
cursor.moveToFirst();
a = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ALBUM_ID));
Picasso.with(this)
.load(Uri.parse("file://"+a))
.error(R.drawable.color_music_player_logo)
.into(iv);
推荐答案
为毕加索的图像提供绝对路径,如下所示:
Give Picasso absolute path to your image like this:
String name = "image.jpeg";
String dir = Environment.getExternalStorageDirectory().getAbsolutePath();
Picasso.with(context).load(new File(dir + File.separator + name)).into(iv);
或者您可以使用filechooser
,以便选择要加载的图像或显示图像列表,然后onclick为您加载图像....
or you can use filechooser
so you can select which image to load or show list of images and onclick loads an image for you ....
这篇关于使用毕加索显示音乐的专辑封面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文