Question

A project I'm currently working on requires the application to discover all audio tracks on an android device. In addition to the tracks, it must also be able to group them by album and artist.

I found the MediaStore content provider and set about creating a database helper utility class to quickly return the IDs of tracks, albums and artists. I have been able to query the Media Store which returns some result, but it appears that not all of the audio information is stored there.

For example, querying for all artists returns only 9 results, but the Android Music Player application returns 27.

I am using the following code to query the artists:

ContentResolver resolver = getContentResolver();
String[] projection = new String[]{MediaStore.Audio.ArtistColumns.ARTIST};
Uri uri = android.provider.MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI;

Cursor c = null;

    try {
        c = resolver.query(uri, projection, null, null, null);
    } 
    catch (UnsupportedOperationException e) {
        Log.e("DatabaseHelper", "query: " + e);
        c = null;
    }

    if(c != null) {
        while(c.isAfterLast() == false) {
            Log.e("ARTIST", "NAME: " + cursor.getString(0));
            cursor.moveToNext();
        }
    }

It seems as if the Media Scanner (which is definatley run when my device boots up) is not detecting much of my audio library. Am I doing something wrong?

I am simply trying to find all audio tracks, audio albums and audio artists quickly and efficiently. If MediaStore can't help me then I fear I will have to implement some form of file scanner to traverse directory structures and build my own database, but I don't want to do that ;)

Any thoughts would be much appreciated.

Thanks.

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top