android音乐播放器扫描仪

android音乐播放器扫描仪,android,mediastore,Android,Mediastore,我想创建只显示包含音乐的文件夹的扫描仪。我只知道如何创建使用MediaStore从path获取音乐的查询 public static QueryTask buildFileQuery(String path, String[] projection) { // It would be better to use selectionArgs to pass path here, but there // doesn't appear to be any way to pass th

我想创建只显示包含音乐的文件夹的扫描仪。我只知道如何创建使用MediaStore从path获取音乐的查询

public static QueryTask buildFileQuery(String path, String[] projection)
{
    // It would be better to use selectionArgs to pass path here, but there
    // doesn't appear to be any way to pass the * when using it.
    StringBuilder selection = new StringBuilder();
    selection.append("_data GLOB ");
    DatabaseUtils.appendEscapedSQLString(selection, path);
     // delete the quotation mark added by the escape method
    selection.deleteCharAt(selection.length() - 1);
    selection.append("*' AND is_music!=0");

    Uri media = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
    QueryTask result = new QueryTask(media, projection, selection.toString(), null, DEFAULT_SORT);
    result.type = TYPE_FILE;
    return result;
}

MediaStore.Audio.Media.DATA
列包含文件路径

    Cursor c = getContentResolver().query(
            MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
            new String[]{MediaStore.Audio.Media.TITLE, MediaStore.Audio.Media.DATA},
            MediaStore.Audio.Media.IS_MUSIC + "=1",
            null,
            MediaStore.Audio.Media.DATA
    );

    if (c.moveToFirst()) {
        do {
            Log.d("T", c.getString(0) + " -- " + c.getString(1));
        } while (c.moveToNext());
    }
这将输出以下内容:

Come On -- /storage/emulated/0/Music/The Rolling Stones/More Hot Rocks Big Hits & Fazed Cookies (Disc 2)/10 Come On.mp3
...

一旦有了路径,您就可以恢复文件夹层次结构了

是否要显示sd卡上显示的文件夹?是的,我要显示包含音乐的文件夹