I want to be able to get the album art of the song that is currently playing. I am able to get the name, album, artist with the use of
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
String cmd = intent.getStringExtra("command");
Log.v("tag ", action + " / " + cmd);
String artist = intent.getStringExtra("artist");
String album = intent.getStringExtra("album");
String track = intent.getStringExtra("track");
Log.v("tag", artist + ":" + album + ":" + track);
Fullname = (artist + ":" + album + ":" + track);
Toast.makeText(MusicPlayer.this, track, Toast.LENGTH_SHORT).show();
update();
However, this does not help me with getting album art. Most of the posts on here that ask for getting album art call for the use of
MediaStore.Audio.AlbumColumns.AlbumArt
But I can't seem to figure out how to work it. When I tried to use
Cursor cursor = getActivity().managedQuery(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));
// do whatever you need to do
}
(From here ) or anything similar to this I keep running into the problem of not having a albumId. I read that I should set albumid to
album_id = cursor.getLong(cursor.getColumnIndex(MediaStore.Audio.Media.ALBUM_ID))
but I can't seem to get a Long without having another cursor which I can't figure out how to do to without the use of a pre-existing albumid. Any help would be greatly appreciated.