问题
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.
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);
回答1:
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);
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 ....
来源:https://stackoverflow.com/questions/42623276/displaying-album-art-for-music-using-picasso