0

I want to load the cover art of a Audio/Music file which is present in Internal Storage of the device.

I Only have the path to the file.

This is what I have tried till now-

I have referred this Issue which show the solution.

But I don't know how to exactly create an new Module, as from what information I could gather online is we have to register the Module first then use them

Any one who could guide me on how to register the Module and then load the cover art would be really helpful.

Also I have tried loading the cover art the normal way like but it does not load the cover art.

GlideApp
    .with(myFragment)
    .load(url)
    .centerCrop()
    .placeholder(R.drawable.loading_spinner)
    .into(myImageView);
  • Possible duplicate of [cover art on android](https://stackoverflow.com/questions/1954434/cover-art-on-android) – Nilesh Deokar Nov 14 '17 at 07:49
  • @NileshDeokar Sorry for responding late. I only have the path to the audio file. Can you please help with that. –  Nov 21 '17 at 10:29

1 Answers1

4

If this is the path you are having :

/storage/emulated/0/Download/mysong.mp3

Then you can use following function :

public void getAudioAlbumImageContentUri(Context context, String filePath) {
        Uri audioUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
        String selection = MediaStore.Audio.Media.DATA + "=? ";
        String[] projection = new String[] { MediaStore.Audio.Media._ID , MediaStore.Audio.Media.ALBUM_ID};

        Cursor cursor = context.getContentResolver().query(
                audioUri,
                projection,
                selection,
                new String[] { filePath }, null);

        if (cursor != null && cursor.moveToFirst()) {
            long albumId = cursor.getLong(cursor.getColumnIndex(MediaStore.Audio.Media.ALBUM_ID));
            Uri sArtworkUri = Uri.parse("content://media/external/audio/albumart");
            Uri imgUri = ContentUris.withAppendedId(sArtworkUri,
                    albumId);
            Log.d(TAG,"AudioCoverImgUri = "+ imgUri.toString());

            Glide.with(this)
                    .load(imgUri)
                    .into(((ImageView)findViewById(R.id.button)));

            cursor.close();
        }
    }
Nilesh Deokar
  • 2,975
  • 30
  • 53