1

使用这种从 Android 的外部存储中检索音频文件的方法

Cursor cursor = getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, null, null, null, null);

我真的可以找到一种合理的方式来获取给定歌曲的流派吗?MediaStore 类似乎提供了其他所有东西——从歌曲的标题到它的作曲家信息——除了流派字段。那我应该使用 MediaMetadataRetriever 吗?如果是这样,为设备上的每首歌曲创建一个 MediaMetadataRetriever 实例会在多大程度上降低应用程序的性能?

也许有一些更好的方法可以从 android 的外部和内部存储中检索所有音频文件?

4

1 回答 1

1

开发者网站所述,

您可以使用MediaStore.Audio.Genres获取音频文件的流派

示例代码:

private static String[] genresProj = {
            MediaStore.Audio.Genres.NAME,
            MediaStore.Audio.Genres._ID
    };

 int idIndex = cursor
                .getColumnIndexOrThrow(MediaStore.Audio.Media._ID);

 while (cursor.moveToNext()){
                int id = Integer.parseInt(mediaCursor.getString(idIndex));

                Uri uri = MediaStore.Audio.Genres.getContentUriForAudioId("external", id );
                genresCursor = context.getContentResolver().query(uri,
                        genresProj , null, null, null);
                int genreIndex = genresCursor.getColumnIndexOrThrow(MediaStore.Audio.Genres.NAME);                


                    while (genresCursor.moveToNext()) {
                        Log.d(TAG, "Genre = " +genresCursor.getString(genreIndex));
                    }

            }
        }

要获取音频文件的其他详细信息,请在此处查看

于 2017-09-27T04:53:09.400 回答