【问题标题】:Is there any way to fetch song's genre using MediaStore?有没有办法使用 MediaStore 获取歌曲的流派?
【发布时间】:2018-03-08 06:38:18
【问题描述】:

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

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

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

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

【问题讨论】:

    标签: android mediastore mediametadataretriever


    【解决方案1】:

    Developer's Site 所述,

    您可以使用 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));
                        }
    
                }
            }
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多