I'm going to bring up the music on my Android phone in a list format. How can I retrieve the music title, album, and singer information on the device and present it in a list format?

Asked 2 years ago, Updated 2 years ago, 25 views

I'm going to bring up the music on my Android phone in a list format. How can I retrieve the music title, album, and singer information on the device and present it in a list format?

java android

2022-09-22 21:12

2 Answers

Android provides meta-information on media such as images, audio, and video through MediaStore providers. In other words, media meta-information is stored in a database and can be easily imported through queries. Please refer to the following code to print out the audio information.

Cursor cursor = null;
try {
    cursor = getActivity().getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, null, null, null, null);
    if (cursor != null) {
        while (cursor.moveToNext()) {
            String title = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.TITLE));
            String artist = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ARTIST));
            String album = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ALBUM));
            long duration = cursor.getLong(cursor.getColumnIndex(MediaStore.Audio.Media.DURATION));
            String path = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.DATA));

            ...
        }

    }
} } finally {
    if (cursor != null) {
        cursor.close();
    }
}


2022-09-22 21:12

http://tkddlf4209.blog.me/220746210643

There's an example I made You have all the functions you asked.


2022-09-22 21:12

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.