1

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

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

so can anyone help me in this??

Thanks in advance

Ayush Katoch
  • 11
  • 1
  • 5

2 Answers2

1

You can use content provider for this.

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();
 }

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;
    }
Jay Shah
  • 732
  • 4
  • 16
0

Google has a great example of a music player for phone , chromecast and AUTO on Github https://github.com/googlesamples/android-UniversalMusicPlayer

CkurtM
  • 195
  • 6