akshay7692
akshay7692

Reputation: 601

Column "album_id" doesnt exists in MediaStore.Audio.Artists.Albums

I want to query MediaStore.Audio.Artists.Albums table to get albums by given artist. I successfully queried all artists names and artist id from MediaStore.Audio.Artists table but I am unable to get album_id from MediaStore.Audio.Artists.Albums table. I am getting following error :

java.lang.IllegalArgumentException: column 'album_id' does not exist

However column "album_id" should be present in MediaStore.Audio.Artists.Albums table as per documentation. I checked all columns from MediaStore.Audio.Artists.Albums as follows :

Uri artistAlbumsUri =  MediaStore.Audio.Artists.Albums.getContentUri("external", artistId);
Cursor c = mContentResolver.query(artistAlbumsUri,null, null, null, null);

// print all column names
for(int i = 0; i < c.getColumnCount(); i++)
     Log.d(TAG,"Column name:"+c.getColumnName(i));

The log output is as follows :

Column name:album_art
Column name:artist
Column name:minyear
Column name:album
Column name:artist_key
Column name:album_key
Column name:_id
Column name:numsongs_by_artist
Column name:artist
Column name:numsongs
Column name:maxyear

Notice that artist column appears twice and there is _id column instead of album_id.Is it a bug or am I missing something ?

Edit: I was testing above code on Android Marshmallow device

Upvotes: 1

Views: 587

Answers (3)

Dipto Debnath
Dipto Debnath

Reputation: 11

You can use MediaMetadataRetriever for getting imagefile from audio. check the documentation https://developer.android.com/reference/android/media/MediaMetadataRetriever

byte[] image = getSongMediaImage(use_your_song_path)
        Glide.with(context).load(image).into(holder.songThumb)



  private byte[] getSongMediaImage(String path){
    MediaMetadataRetriever mediaMetadataRetriever=new MediaMetadataRetriever();
    mediaMetadataRetriever.setDataSource(path);
    byte[] image=mediaDataretriever.getEmbeddedPicture();
    mediaMetadataRetriever.release();
    }

Upvotes: 0

TomDuan
TomDuan

Reputation: 116

did you uninstall your app? and reinstall your app

when i used greenDAO and changed my db,i had similar error

Upvotes: 0

akshay7692
akshay7692

Reputation: 601

I tried to use "_id" column to fetch corresponding album art and it seems that it is actually an album_id column. So for others having same issue, you will have to use "_id" as the column name while querying instead of MediaStore.Audio.Artists.Albums.ALBUM_ID column which has value "album_id".

Upvotes: 2

Related Questions