displaying album art for music using picasso

一笑奈何 提交于 2019-12-11 08:26:49

问题


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.

  1. 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);
    
  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!