我正在尝试实现的是在数组列表中获取所有mp3文件的URL和标题以返回它。全部来自以下文件夹:/ ext_card / Music /和所有子文件夹。

我探索过的所有选项似乎都卡住了,我在互联网上查找的所有答案都指向了媒体存储,但我不知道如何使用它

而且不要给我RTFM的废话,因为我对mediastore的解释充其量是迟钝的。

所以有人可以帮我吗,或者给我一个简单的可以查询所有mp3文件的mediastore示例?

最佳答案

使用它可以帮助您从SD卡中获取所有MP3歌曲

private static ArrayList<genericSongClass> songs = null;

public void BindAllSongs() {
        /** Making custom drawable */
        String selection = MediaStore.Audio.Media.IS_MUSIC + " != 0";
        final String[] projection = new String[] {
                MediaStore.Audio.Media.DISPLAY_NAME,
                MediaStore.Audio.Media.ARTIST,
                MediaStore.Audio.Media.DATA};
                final String sortOrder = MediaStore.Audio.AudioColumns.TITLE
                        + " COLLATE LOCALIZED ASC";

                try {
                    // the uri of the table that we want to query
                    Uri uri = android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
                    // query the db
                    cursor = getBaseContext().getContentResolver().query(uri,
                            projection, selection, null, sortOrder);
                    if (cursor != null) {
                        songs = new ArrayList<genericSongClass>(cursor.getCount());
                        cursor.moveToFirst();
                        while (!cursor.isAfterLast()) {
                            GSC = new genericSongClass();
                            GSC.songTitle = cursor.getString(0);
                            GSC.songArtist = cursor.getString(1);
                            GSC.songData = cursor.getString(2);
                            songs.add(GSC);
                            cursor.moveToNext();
                        }
                    }
                } catch (Exception ex) {

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

    }

public class genericSongClass {
        String songTitle = "";
        String songArtist = "";
        String songData = "";
        String isChecked = "false";
}

10-07 19:25
查看更多