yosaga
yosaga

Reputation: 15

How to use Picasso for retrieving Album Art from .mp3 file

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

Upvotes: 1

Views: 396

Answers (1)

Kaushal28
Kaushal28

Reputation: 5555

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.

Upvotes: 1

Related Questions