我正在尝试在我的应用中播放歌曲。但我无法从专辑栏目中获得专辑封面。我不想使用MediaMetadataRetriever
,因为当我填充列表时它会占用大量内存。这是代码:
ContentResolver musicResolver = getActivity().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 albumArtColumn = musicCursor.getColumnIndex(MediaStore.Audio.AlbumColumns.ALBUM_ART);
}
我到处寻找它但找不到合适的答案。
0 {
_id=11874
_data=/storage/emulated/0/Music/Bang Bang (2014)/01 - Tu Meri - DownloadMing.SE.mp3
_display_name=01 - Tu Meri - DownloadMing.SE.mp3
_size=8349428
mime_type=audio/mpeg
date_added=1437797205
is_drm=0
date_modified=1435229092
title=Tu Meri - DownloadMing.SE
title_key= O Q A 1 K 9
/ E U C ? E ) / A 9 C 5 M 1
duration=257149
artist_id=5
composer=Music: Shekhar Ravjiani & Vishal Dadlani | DownloadMing.SE
album_id=5
track=0
year=2014
is_ringtone=0
is_music=1
is_alarm=null
is_notification=0
is_podcast=null
bookmark=null
album_artist=DownloadMing.SE
artist_id:1=5
artist_key= S 9 M 7 ) ? / ) / ? ) C 9
artist=Vishal Dadlani
album_id:1=5
album_key= + ) C 5 + ) C 5 462492867
album=Bang Bang (2014)
}
1 {
_id=11875
_data=/storage/emulated/0/Music/Bang Bang (2014)/02 - Meherbaan - DownloadMing.SE.mp3
_display_name=02 - Meherbaan - DownloadMing.SE.mp3
_size=10255537
mime_type=audio/mpeg
date_added=1437797205
is_drm=0
date_modified=1435229093
title=Meherbaan - DownloadMing.SE
title_key= A 1 7 1 K + ) ) C
/ E U C ? E ) / A 9 C 5 M 1
duration=307461
artist_id=6
composer=Music: Shekhar Ravjiani & Vishal Dadlani | DownloadMing.SE
album_id=5
track=0
year=2014
is_ringtone=0
is_music=1
is_alarm=null
is_notification=0
is_podcast=null
bookmark=null
album_artist=DownloadMing.SE
artist_id:1=6
artist_key= ) M 7 = 9 C 5 M 7 9 ? G ) K ) E M 7 1 = 7 ) K K ) S ; 9 ) C 9
artist=Ash King, Shilpa Rao & Shekhar Ravjiani
album_id:1=5
album_key= + ) C 5 + ) C 5 462492867
album=Bang Bang (2014)
}
2 {
_id=11876
_data=/storage/emulated/0/Music/Bang Bang (2014)/03 - Uff - DownloadMing.SE.mp3
_display_name=03 - Uff - DownloadMing.SE.mp3
_size=9049421
mime_type=audio/mpeg
date_added=1437797205
is_drm=0
date_modified=1435229093
title=Uff - DownloadMing.SE
title_key= Q 3 3
/ E U C ? E ) / A 9 C 5 M 1
duration=272170
artist_id=7
composer=Music: Shekhar Ravjiani & Vishal Dadlani | DownloadMing.SE
album_id=5
track=0
year=2014
is_ringtone=0
is_music=1
is_alarm=null
is_notification=0
is_podcast=null
bookmark=null
album_artist=DownloadMing.SE
artist_id:1=7
artist_key= 7 ) K M 7 / 1 1 G = ) Q K + 1 C C Y / ) Y ) ?
artist=Harshdeep Kaur & Benny Dayal
album_id:1=5
album_key= + ) C 5 + ) C 5 462492867
album=Bang Bang (2014)
}
3 {
_id=11877
_data=/storage/emulated/0/Music/Bang Bang (2014)/04 - Bang Bang - DownloadMing.SE.mp3
_display_name=04 - Bang Bang - DownloadMing.SE.mp3
_size=10613831
mime_type=audio/mpeg
date_added=1437797205
is_drm=0
date_modified=1435229094
title=Bang Bang - DownloadMing.SE
title_key= + ) C 5 + ) C 5
/ E U C ? E ) / A 9 C 5 M 1
duration=320078
artist_id=8
composer=Music: Shekhar Ravjiani & Vishal Dadlani | DownloadMing.SE
album_id=5
track=0
year=2014
is_ringtone=0
is_music=1
is_alarm=null
is_notification=0
is_podcast=null
bookmark=null
album_artist=DownloadMing.SE
artist_id:1=8
artist_key= + 1 C C Y / ) Y ) ? C 1 1 O 9 A E 7 ) C
artist=Benny Dayal & Neeti Mohan
album_id:1=5
album_key= + ) C 5 + ) C 5 462492867
album=Bang Bang (2014)
}
4 {
_id=11878
_data=/storage/emulated/0/Music/Bang Bang (2014)/05 - Meherbaan (Reprise) - DownloadMing.SE.mp3
_display_name=05 - Meherbaan (Reprise) - DownloadMing.SE.mp3
_size=5858173
mime_type=audio/mpeg
date_added=1437797205
is_drm=0
date_modified=1435229095
title=Meherbaan (Reprise) - DownloadMing.SE
title_key= A 1 7 1 K + ) ) C K 1 G K 9 M 1
/ E U C ? E ) / A 9 C 5 M 1
duration=181551
artist_id=9
composer=Music: Shekhar Ravjiani & Vishal Dadlani | DownloadMing.SE
album_id=5
答案 0 :(得分:0)
我收到MediaStore.Audio.AlbumColumns.ALBUM_ART returns -1
的原因是因为我已将URI MediaStore.Audio.Media
的光标设为MediaStore.Audio.AlbumColumns
。
感谢@pskink的帮助。