如何显示专辑封面,歌曲名称,时间,以及艺术家的名字在ListView [英] How to show album art , song name ,duration, and the artist name in a ListView

查看:287
本文介绍了如何显示专辑封面,歌曲名称,时间,以及艺术家的名字在ListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我想打的,一个android音乐应用程序,我希望我的ListView,显示所有的歌曲,以显示歌曲,歌手名,持续时间和歌曲名称的专辑封面

hello i wanna make an android music app for that i want my listView which shows all the songs to display album art of that song , artist name , duration and song name

我已经成功显示ListView中的所有歌曲,但无法显示专辑封面等。

i have succeeded showing all the songs in the listview but unable to display album art etc

所以任何人都可以帮我在这?

so can anyone help me in this??

在此先感谢

推荐答案

您可以使用内容提供商这一点。

You can use content provider for this.

希望这code可以帮助你启动。

Hope this code may help you to start up.

final Cursor mCursor = getContentResolver().query(
                MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
                new String[] { MediaStore.Audio.Media.DISPLAY_NAME,
                        MediaStore.Audio.Media.DATA,
                        MediaStore.Audio.Media.ARTIST,
                        MediaStore.Audio.Media.ALBUM_ID }, null, null,
                "LOWER(" + MediaStore.Audio.Media.TITLE + ") ASC");

        int count = mCursor.getCount();

        String[] songs = new String[count];

        if (mCursor.moveToFirst()) {
            do {
                String songname = mCursor
                        .getString(mCursor
                                .getColumnIndexOrThrow(MediaStore.Audio.Media.DISPLAY_NAME));
                String sonpath = mCursor.getString(mCursor
                        .getColumnIndexOrThrow(MediaStore.Audio.Media.DATA));
                String artistname = mCursor.getString(mCursor
                        .getColumnIndexOrThrow(MediaStore.Audio.Media.ARTIST));
                String albumid = mCursor
                        .getString(mCursor
                                .getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM_ID));
    } while (mCursor.moveToNext());
            Constant.sdCardmusic = allsongs;
        }

        mCursor.close();
 }

如果你想获得相册图片,那么你可以通过相册ID从上面code进入下面的方法:

If you want to get album picture then you can pass album id getting from above code into below method:

private Bitmap getArtistImage(String albumid) {
        Bitmap artwork = null;
        try {
            Uri sArtworkUri = Uri
                    .parse("content://media/external/audio/albumart");
            Uri uri = ContentUris.withAppendedId(sArtworkUri,
                    Long.valueOf(albumid));
            ContentResolver res = mContext.getContentResolver();
            InputStream in = res.openInputStream(uri);
            artwork = BitmapFactory.decodeStream(in);

        } catch (Exception e) {
            Log.e("Exception", e.toString());
        }
        return artwork;
    }

这篇关于如何显示专辑封面,歌曲名称,时间,以及艺术家的名字在ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆