1

I'm trying to retrieve Album Art from a single .mp3 file using Picasso but I am unable to do so. Whenever the application starts it shows nothing.

Here is my code:

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

    getInit();

    String path = "/root/sdcard/Bom Diggy Diggy.mp3";

    Picasso.with(this).load(new File(path)).into(album_art);
}

public void getInit() {
    album_art = (ImageView) findViewById(R.id.album_art);
}

I also tried using cursor for getting Album Art but it do not work. Any help would be appreciated. Thank You

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
yosaga
  • 15
  • 8

1 Answers1

1

You have to give the path of the image in picasso load() method, not the path of .mp3 file. So for getting the path of album art for any mp3 file you need to use content resolver as following.

Cursor cursor = getContentResolver().query(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, 
            new String[] {MediaStore.Audio.Albums._ID, MediaStore.Audio.Albums.ALBUM_ART}, 
            MediaStore.Audio.Albums._ID+ "=?", 
            new String[] {String.valueOf(albumId)}, 
            null);

if (cursor.moveToFirst()) {
    String path = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Albums.ALBUM_ART));
    Picasso.with(this).load(new File(path)).into(album_art);
}

Here, albumId refers to MediaStore.Audio.Media.ALBUM_ID for that song.

If you're are looking for album art for a particular song (rather than in a list of albums), as far as I know it's a two-stage process since ALBUM_ART is a property of MediaStore.Audio.Albums and is not available directly as song metadata.

For more information about getting path of album art refer this.

Kaushal28
  • 5,377
  • 5
  • 41
  • 72
  • I tried your code but nothing shows up, do you know any other way? All I want is to get the album art from song and display it on Imageview – yosaga May 19 '18 at 13:25
  • And the link you gave..I read those answer before and nothing works – yosaga May 19 '18 at 13:29