我怎么能显示专辑封面使用MediaStore.Audio.Albums.ALBUM_ART? [英] How can I display Album Art using MediaStore.Audio.Albums.ALBUM_ART?
问题描述
我试图建立一个MP3播放器,我想ImageView的显示各自的歌曲的专辑封面。我已经试过以下,但它不能正常工作。
I'm trying to build a MP3 player and I want the ImageView to display the album art of respective songs. I've tried the following, but it doesn't work.
albumcover = (ImageView) findViewById(R.id.cover);
String coverPath = songsList.get(songIndex).get(MediaStore.Audio.Albums.ALBUM_ART);
Drawable img = Drawable.createFromPath(coverPath);
albumcover.setImageDrawable(img);
当我尝试播放的歌曲,我得到的是在ImageView的一个空白屏幕。
When I try to play the songs, all I get is a blank screen in the ImageView.
推荐答案
下面是我如何获得专辑封面一首歌曲:
Here's how I get album art for a song:
Cursor cursor = getActivity().managedQuery(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI,
new String[] {MediaStore.Audio.Albums._ID, MediaStore.Audio.Albums.ALBUM_ART},
MediaStore.Audio.Albums._ID+ "=?",
new String[] {String.valueOf(albumId)},
null);
if (cursor.moveToFirst()) {
String path = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Albums.ALBUM_ART));
// do whatever you need to do
}
ALBUMID
引用 MediaStore.Audio.Media.ALBUM_ID
这首歌。
如果你正在寻找专辑封面特定歌曲(而不是在专辑列表),据我知道这是因为 ALBUM_ART $ C $一个两阶段的过程C>是
MediaStore.Audio.Albums
,并不能直接作为歌曲的元数据。
If you're are looking for album art for a particular song (rather than in a list of albums), as far as I know it's a two-stage process since ALBUM_ART
is a property of MediaStore.Audio.Albums
and is not available directly as song metadata.
这篇关于我怎么能显示专辑封面使用MediaStore.Audio.Albums.ALBUM_ART?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!