0

So i'm trying to build a very simple music player (I started working with android just a few days ago). Till now I wrote the code to retrieve songs informations. However I'm not able to retrieve the album art for every single media. I know there is a column ALBUM_ART in MediaStore.Audio.Album (I tried to retrieve the Album art for each album and it worked), but I want to assign the album art to each song and I don't know how to do it. Surfing the net I found this kind of code:

Uri sArtworkUri = Uri.parse("content://media/external/audio/albumart");
Uri albumArtUri = ContentUris.withAppendedId(sArtworkUri, albumId);

But it doesn't seem to work, all I get is null. Can someone explain me how to retrieve the album art for each song?

4

1 回答 1

0

字符串 [] 列 = { android.provider.MediaStore.Audio.Albums._ID, android.provider. MediaStore.Audio.Albums.ALBUM,android.provider.MediaStore.Audio.Albums.ALBUM_ART }; int 专辑_column_index = 0; 光标 cursor = getActivity().managedQuery(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, 列, null, null, null);

        if (cursor.moveToFirst()) {
            do {


                arrAlbumNAme.add( cursor.getString(cursor
                        .getColumnIndex(android.provider.MediaStore.Audio.Albums.ALBUM)));
                album_column_index = cursor.getColumnIndexOrThrow(android.provider.MediaStore.Audio.Albums._ID);
                //cursor.moveToPosition(position);
                albumID = cursor.getInt(album_column_index);
                Uri sArtworkUri = Uri.parse("content://media/external/audio/albumart");
                Uri uri = ContentUris.withAppendedId(sArtworkUri, albumID);
                arrAlbumArt.add(cursor.getString(cursor
                        .getColumnIndex(android.provider.MediaStore.Audio.Albums.ALBUM_ART)));

            } while (cursor.moveToNext());
        }

内部适配器 holder.image_icon.setImageUri(arrAlbumArt.get(position));

于 2014-10-16T07:02:03.643 回答