Reputation: 2793
I am currently creating a music player and I am retrieving the music on the device using a Cursor as such
mCursor = getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
requestedColumns, null, null, null);
where
private String[] requestedColumns =
{
MediaStore.Audio.Media.TITLE,
MediaStore.Audio.Media._ID,
MediaStore.Audio.Media.DATA,
MediaStore.Audio.Media.ALBUM,
MediaStore.Audio.Media.ALBUM_ID,
MediaStore.Audio.Media.ARTIST,
MediaStore.Audio.Media.ARTIST_ID,
MediaStore.Audio.Media.YEAR,
MediaStore.Audio.Media.DURATION,
};
Now this is working perfectly and I am successfully retrieving music on my device/SD Card. My questions is: is there any way to get the Album artist for a particular song? Now I don't simply mean the artist of a partcular the song, but the main artist behind the entire album from which a song belongs. There does not seem to be some kind of MediaStore.Audio.Media.ALBUM_ARTIST
.
On a side note: what is the difference (if any) between using MediaStore.Audio.Media.ALBUM
and MediaStore.Audio.ALBUMS
?
Upvotes: 3
Views: 5030
Reputation: 2042
This works. Do not ask me how though !!
public Cursor getAlbumArtistCursor(Context context) {
ContentResolver cr = context.getContentResolver();
// query all media and get the album_artist field
return cr.query(
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
new String[]{ "album_artist", MediaStore.Audio.Media.ALBUM_ID, MediaStore.Audio.Media.ALBUM, MediaStore.Audio.Media._ID}, null, null, null);
}
Upvotes: 1
Reputation: 542
In my app I noticed the same problems and therefore ran a test with artificial metadata:
I tested with Android 4.4.4 (Cyanogen), Android 6.0.1 (Google) and Android 7.1.2 (AOSP, unofficial). I did not have access to Android 8.0 or 8.1.
Result: Android shows "Artist-A" as album artist. This is obviously incorrect.
There are two bugs in Android:
various
, but it chooses any
instead.Further, the bug #52309 mentioned above has been closed long ago, with comment "obsolete". Even Google Play Music, the reference music player, also suffers from the same bugs, this is nonsense.
So what solutions do we have?
various
in case they do not all match.Upvotes: 0
Reputation: 23279
I think what you are looking for is MediaStore.Audio.Albums.ARTIST
, which you can look up as the second part of a two-stage process.
Cursor cursor = getActivity().managedQuery(
MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI,
new String[] {MediaStore.Audio.Albums._ID, MediaStore.Audio.Albums.ARTIST},
MediaStore.Audio.Albums._ID+ "=?",
new String[] {albumId},
null);
Where albumId
is the album id of the song, ie what you have gotten in your earlier query: MediaStore.Audio.Media.ALBUM_ID
Think of MediaStore.Audio.ALBUMS
as metadata about all your albums. MediaStore.Audio.Media.ALBUM
refers to the album this audio file is from. Media
is always metadata about each individual file.
Upvotes: 2