Q:

How to search for media files in folders and subfolders?

How to search for media files in folders and subfolders quickly on Android device?
I just need boolean result: true of false. If folder or its subfolders contains media files(music files) then true. I tried to search for media files in every folder and subfolder using recursive function but it takes a very long time and crashes for this reason.
Here is code of my recurse function:
directoryName - Path to  folder,
 trackChecker - function that check either file is audio or no.
private boolean FolderWithMusic(String directoryName) {
    File directory = new File(directoryName);
    // get all the files from a directory
    File[] fList = directory.listFiles();
    for (File file : fList) {
        if (file.isFile()) {
            if(trackChecker(file.getName()))
                return true;
        } else if (file.isDirectory() && file.canRead() ) {
            if(FolderWithMusic(file.getAbsolutePath()))
                return true;
            else
                return false;
        }
    }
    return false;
}

I suppose that it should be a managedQuery, but I don't know how to do it for folder. 
I found such query code:
Cursor cursor = managedQuery(
                    MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
                    new String[] { MediaStore.Audio.Media.DISPLAY_NAME,
                            MediaStore.Audio.Media.DATA},
                    MediaStore.Audio.Media.DATA + " like ? OR " + MediaStore.Audio.Media.DATA + " like ? ",
                    new String[] {"%mp3","%wav"},
                    "LOWER(" + MediaStore.Audio.Media.TITLE + ") ASC");
a = cursor.getCount();

But it looks like hardcoding and I need search for audio in folders/subfolders. It seems to me that this query searches for all audio. 
Thank you for help.

A:

Quaick search music in folders and subbfolders:
private boolean FolderWithMusic(String directoryPath){
    Cursor cursor;
    String selection;
    String[] projection = {MediaStore.Audio.Media.IS_MUSIC};
    Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;

//Create query for searching media files in folder
selection = MediaStore.Audio.Media.DATA + " like " + "'%" + directoryPath + "/%'";
cursor = getContentResolver().query(uri, projection, selection, null, null);
if (cursor != null) {
    boolean isDataPresent;
    isDataPresent = cursor.moveToFirst();
    return isDataPresent;
}
return false;
}

If folder contains music - function returns True.

