如何获得类型和显示它们&里面的歌曲使用recyclerView android?

时间:2016-02-26 10:12:57

标签: java android android-studio audio-player android-music-player

我想使用回收者视图获取类型列表,并在视图寻呼机网格中显示它们。我这样做是为了检索专辑,但对如何从曲目中获取流派感到困惑。

我的相册检索代码: -

AlbumRetriever

public class AlbumLoader {
    public static Album getAlbum(Cursor cursor) {
        Album album = new Album();
        if (cursor != null) {
            if (cursor.moveToFirst())
                album = new Album(cursor.getLong(0), cursor.getString(1), cursor.getString(2), cursor.getLong(3), cursor.getInt(4), cursor.getInt(5));
        }
        if (cursor != null)
            cursor.close();
        return album;
    }

    public static List<Album> getAlbumsForCursor(Cursor cursor) {
        ArrayList arrayList = new ArrayList();
        if ((cursor != null) && (cursor.moveToFirst()))
            do {
                arrayList.add(new Album(cursor.getLong(0), 
                                        cursor.getString(1), 
                                        cursor.getString(2), 
                                        cursor.getLong(3), 
                                        cursor.getInt(4), 
                                        cursor.getInt(5)));
            }
            while (cursor.moveToNext());
        if (cursor != null)
            cursor.close();
        return arrayList;
    }

    public static List<Album> getAllAlbums(Context context) {
        return getAlbumsForCursor(makeAlbumCursor(context, null, null));
    }

    public static Album getAlbum(Context context, long id) {
        return getAlbum(makeAlbumCursor(context, "_id=?", new String[]{String.valueOf(id)}));
    }

    public static List<Album> getAlbums(Context context, String paramString) {
        return getAlbumsForCursor(makeAlbumCursor(context, 
                                    "album LIKE ?", 
                                    new String[]{"%" + paramString + "%"}));
    }

    public static Cursor makeAlbumCursor(Context context, String selection, String[] paramArrayOfString) {
        final String albumSortOrder = musixone.com.musixplayer.Utils
                        .PreferencesUtility.getInstance(context).getAlbumSortOrder();
        Cursor cursor = context.getContentResolver().query(
                        MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, 
                        new String[]{"_id", "album", "artist", "artist_id", "numsongs", "minyear"}, 
                        selection, paramArrayOfString, albumSortOrder);

        return cursor;
    }
}

我也制作了一个专辑类对象。如何去检索类型?

0 个答案:

没有答案