No “number_of_albums column” in MediaStore.Audio.Artists

我的梦境 提交于 2019-12-24 17:00:58

问题


I want to retrieve data from MediaStore especially the number of albums per artist but SQLite throws me an exception

no such column: number_of_albums (code 1): while compiling: SELECT artist_key, artist, number_of_albums FROM audio WHERE (is_music != 0)

Can someone explain me what I am doing wrong?

My code :

private List<Artist> getArtistList() {
    String selection = MediaStore.Audio.Media.IS_MUSIC + " != 0";

    String[] projection = {
            MediaStore.Audio.Artists.ARTIST_KEY,
            MediaStore.Audio.Artists.ARTIST,
            MediaStore.Audio.Artists.NUMBER_OF_ALBUMS
    };

    Cursor cursor = this.getActivity().getApplicationContext().getContentResolver().query(
            MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
            projection,
            selection,
            null,
            null);

    List<Artist> artists = new ArrayList<Artist>();
    Artist tmp = null;

    if (cursor.moveToFirst()) {
        do {    
            tmp = new Artist(cursor.getString(0),
                    cursor.getString(1),
                    Integer.parseInt(cursor.getString(2)));
            artists.add(tmp);
        } while (cursor.moveToNext());
    }

    return artists;
}

Thanks !


回答1:


You're querying the wrong content URI for that column. Use MediaStore.Audio.Artists.EXTERNAL_CONTENT_URI instead of MediaStore.Audio.Media.EXTERNAL_CONTENT_URI.



来源:https://stackoverflow.com/questions/22244673/no-number-of-albums-column-in-mediastore-audio-artists

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!