我正在创建一个音乐应用程序,我需要在其中显示歌手名称歌曲标题等,但我想要的是获得该特定歌曲的图像我也尝试了很多但却无法正常使用
Here is the code
ContentResolver musicResolver = getContentResolver();
Uri musicUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
Cursor musicCursor = musicResolver.query(musicUri, null, null, null, null);
if (musicCursor != null && musicCursor.moveToFirst()) {
int titleColumn = musicCursor.getColumnIndex
(MediaStore.Audio.Media.TITLE);
int idColumn = musicCursor.getColumnIndex
(MediaStore.Audio.Media._ID);
int artistColumn = musicCursor.getColumnIndex
(MediaStore.Audio.Media.ARTIST);
int album = musicCursor.getColumnIndex
(MediaStore.Audio.Media.ALBUM);
int album_art = musicCursor.getColumnIndex
(MediaStore.Audio.Albums.ALBUM_ART);
do {
long thisId = musicCursor.getLong(idColumn);
String thisTitle = musicCursor.getString(titleColumn);
String thisArtist = musicCursor.getString(artistColumn);
String albumName = musicCursor.getString(album);
String albumArt = musicCursor.getString(album_art);
songList.add(new Song(thisId, thisTitle, thisArtist, albumName, albumArt));
}
while (musicCursor.moveToNext());
}
}
I tried but while debugging log cat showing this error
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.lenovodesktop.musicplayerapplication/com.example.lenovodesktop.musicplayerapplication.PlayList}: java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
Caused by: java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
at android.database.CursorWindow.nativeGetString(Native Method)
at android.database.CursorWindow.getString(CursorWindow.java:434)
at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:51)
at android.database.CursorWrapper.getString(CursorWrapper.java:114)
at com.example.lenovodesktop.musicplayerapplication.PlayList.getSongList(PlayList.java:69)
Here I am using cursor for fetching information of song available in sd card
everything is woking fine but when I tried to fetch images for song it gave me above error