Why doesn't MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI give an exact "album artist"?

I work with android MediaStore. I can get a list of music on the device and all the details associated with each element of multimedia (name, artist, duration, etc.).

I would like to be able to show a list of albums with their album.

To be clear, each track has an Artist, for example, "NoFX", but if the track is on a compilation CD, for example, Punk-O-Rama, the Artist is "NoFX", but the Album Artist is likely to be something like " NoFX ", Various artists. "

I reviewed this question here:

Android - Getting album artist from cursor

and I'm trying to implement using MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI and MediaStore.Audio.Albums.ARTIST. However, this does not seem to return the correct result.

Looking at the Android source code, I see that this is actually the album_artist field for MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, but it is marked as "@hide". (see line ~ 1170 at https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/java/android/provider/MediaStore.java ).

I found this field while looking at other [related] Android source code: https://android.googlesource.com/platform/development/+/master/apps/Development/src/com/android/development/MediaScannerActivity.java

I wrote a simple application / event to check this out:

package com.ma.albumartisttest; import android.app.Activity; import android.database.Cursor; import android.os.Bundle; import android.provider.MediaStore; import android.util.Log; import android.util.SparseArray; import android.widget.TextView; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // query all media and get the album_artist field Cursor cursor = getContentResolver().query( MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, new String[]{MediaStore.Audio.Media.ALBUM_ID, "album_artist"}, null, null, null); // Store an id=>name map SparseArray<String> albumArtistNames = new SparseArray<String>(); if (cursor != null) { for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { String mediaAlbumArtist = cursor.getString(1); if (mediaAlbumArtist != null && mediaAlbumArtist.toLowerCase().contains("various")) { // loop through the cursor, save "album_artist"s that look like "various" albumArtistNames.put((int) cursor.getLong(0), mediaAlbumArtist); } } cursor.close(); } String msg; if (albumArtistNames.size() == 0) { msg = "No 'various' artists found!"; Log.d("TESTALBUMARTIST", msg); } else { StringBuffer out = new StringBuffer(); for (int i = 0; i < albumArtistNames.size(); i++) { // loop through the albums found above int albumId = albumArtistNames.keyAt(i); String album_artist = albumArtistNames.get(albumId); Cursor albumCursor = getContentResolver().query( MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, new String[]{MediaStore.Audio.Albums._ID, MediaStore.Audio.Albums.ARTIST}, MediaStore.Audio.Albums._ID + "=?", new String[]{"" + albumId}, null); if (albumCursor != null) { if (albumCursor.moveToFirst()) { // print out what was found. String artistFromAlbumsDB = albumCursor.getString(1); Log.d("TESTALBUMARTIST", album_artist + ":" + artistFromAlbumsDB); out.append("Album id: " + albumId).append('\n') .append("Artist from media table: " + album_artist).append('\n') .append("Artist from albums table: " + artistFromAlbumsDB) .append("\n\n"); } albumCursor.close(); } } msg = out.toString(); } // show the results on-screen TextView tv = new TextView(this); tv.setText(msg); setContentView(tv); } } 

This operation produces the following logcat output:

 12-20 14:16:45.688 22009-22009/com.ma.albumartisttest D/TESTALBUMARTIST﹕ Various Artists:Mike Garson 12-20 14:16:45.708 22009-22009/com.ma.albumartisttest D/TESTALBUMARTIST﹕ Various Artists:Franco Corelli 12-20 14:16:45.728 22009-22009/com.ma.albumartisttest D/TESTALBUMARTIST﹕ Various Artists:The Foreshadowing 12-20 14:16:45.748 22009-22009/com.ma.albumartisttest D/TESTALBUMARTIST﹕ Various Artists - Polyvinyl Record Co:Volcano, I'm Still Excited!! 12-20 14:16:45.778 22009-22009/com.ma.albumartisttest D/TESTALBUMARTIST﹕ Various Artists - Curve Music:GRAND:PM 12-20 14:16:45.808 22009-22009/com.ma.albumartisttest D/TESTALBUMARTIST﹕ Various Artists - DiN:Ian Boddy 12-20 14:16:45.828 22009-22009/com.ma.albumartisttest D/TESTALBUMARTIST﹕ Various Artists:SNFU 12-20 14:16:45.858 22009-22009/com.ma.albumartisttest D/TESTALBUMARTIST﹕ Various Artists:Pulley 12-20 14:16:45.878 22009-22009/com.ma.albumartisttest D/TESTALBUMARTIST﹕ Various Artists:Osker 12-20 14:16:45.908 22009-22009/com.ma.albumartisttest D/TESTALBUMARTIST﹕ Various Artists:Pennywise 12-20 14:16:45.938 22009-22009/com.ma.albumartisttest D/TESTALBUMARTIST﹕ Various Artists:NoFX 12-20 14:16:45.958 22009-22009/com.ma.albumartisttest D/TESTALBUMARTIST﹕ Various Artists:Death By Stereo 12-20 14:16:45.978 22009-22009/com.ma.albumartisttest D/TESTALBUMARTIST﹕ Various Artists (Sillage Intemporel):Sheri Malckin 

I am running this on a Nexus 7 running on 4.4.2. I also tested and saw the same behavior on Huawei Prism II running on 4.1.1

Why doesn’t the simple, and not the “hidden” way of working with albums work?

I expect that album requests will also return "Various Artists".

All help is appreciated.

Visual output of test Application / Activity

+8
android android-contentprovider mediastore
source share
1 answer

I don’t see you defining or importing ListActivity anywhere in your code.

Take a look at these two examples:

0
source share

All Articles