title: How to display thumbnail for audio files in android?
body: <p>I've been trying to have the thumbnail of the audio file in my songslist. But after several attempts I failed to do this. I do not know how to implement this. Is there any easy way to get the thumbnail of the audio file ? I have given the sample picture below that I am actually looking for.</p>
  
  <pre><code>private class MediaCursorAdapter extends SimpleCursorAdapter {
  
      MediaCursorAdapter(Context context, int layout, Cursor c) {
          super(context, layout, c, new String[]{MediaStore.Audio.Media.ARTIST, MediaStore.Audio.Media.TITLE,
                           MediaStore.Audio.Media.ALBUM_ID},
                  new int[]{R.id.title, R.id.displayname, R.id.thumbnail});
      }
  
      @Override
      public void bindView(View view, Context context, Cursor cursor) {
          TextView title = view.findViewById(R.id.title);
          TextView name = view.findViewById(R.id.displayname);
          ImageView thumbnail = view.findViewById(R.id.thumbnail);
  
          MediaMetadataRetriever mmr = new MediaMetadataRetriever();
          byte[] rawArt;
          Bitmap art = null;
          BitmapFactory.Options bfo=new BitmapFactory.Options();
  
          mmr.setDataSource(cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ALBUM_ID)));
          rawArt = mmr.getEmbeddedPicture();
  
          if (null != rawArt)
              art = BitmapFactory.decodeByteArray(rawArt, 0, rawArt.length, bfo);
  
          thumbnail.setImageBitmap(art);
  
          name.setText(cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.TITLE)));
  
          title.setText(cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ARTIST)));
  
  
          view.setTag(cursor.getString(cursor.getColumnIndex(MediaStore.MediaColumns.DATA)));
  
      }
  
      @Override
      public View newView(Context context, Cursor cursor, ViewGroup parent) {
          LayoutInflater inflater = LayoutInflater.from(context);
          View v = inflater.inflate(R.layout.song_list, parent, false);
  
          bindView(v, context, cursor);
  
          return v;
      }
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/C4aVM.png" rel="nofollow noreferrer">Audio thumbnail</a></p>