3

I am now working on a simple music player and i need to get the thumbnail art of all audio files.

String selection = MediaStore.Audio.Media.IS_MUSIC + " != 0";

    String[] projection = {
            MediaStore.Audio.Media._ID,
            MediaStore.Audio.Media.ARTIST,
            MediaStore.Audio.Media.TITLE,
            MediaStore.Audio.Media.DATA,
            MediaStore.Audio.Media.DISPLAY_NAME,
            MediaStore.Audio.Media.DURATION,
            MediaStore.Audio.Media.YEAR
    };
    cursor = getBaseContext().getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
            projection, selection, null, null);
    while(cursor.moveToNext()) {

        name.add(cursor.getString(4));
        path.add(cursor.getString(3));
        duration.add(cursor.getString(5));
    }

how can i get it ? Thanks in advance.

Alex Chengalan
  • 8,211
  • 4
  • 42
  • 56
  • Possible duplicate of [How can I display Album Art using MediaStore.Audio.Albums.ALBUM\_ART?](https://stackoverflow.com/questions/17573972/how-can-i-display-album-art-using-mediastore-audio-albums-album-art) – Yoav Feuerstein Dec 06 '18 at 12:38
  • @YoavFeuerstein I appreciate that you found a better answered question. But this question is asked before your suggested one. Check the asked date. – Alex Chengalan Dec 07 '18 at 04:43

2 Answers2

1

You might want to look at this answer I gave on a similar issue. You will need to give the Uri of the song you to get the cover art on.

Community
  • 1
  • 1
phxhawke
  • 2,581
  • 23
  • 17
  • he asked about `MediaStore`, not `MediaMetadataRetriever` – user924 Sep 17 '17 at 10:23
  • @user924 `MediaMetadataRetriever` is how you access the album art. – phxhawke Sep 28 '18 at 14:46
  • 2
    `MediaMetadataRetriever` is used to get picture directly from audio file (.mp3) which is slow. Android does it for us periodically, so it has Mediastore library from which we can get info and I suppose thumbnail of audio files. I mean author didn't ask general question about how to get thumbnail he asked how to get it using MediaStore – user924 Sep 28 '18 at 16:12
0

According to the documentation, it should be:

Bitmap image = ThumbnailUtils.createAudioThumbnail("your file name", MediaStore.Images.Thumbnails.MICRO_KIND);

This might work for you. (Though it crashes with a NoSuchMethodError in Marshmellow).

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140