title: Android MediaStore get distinct folders of music files
body: <p>Looking for the way to get only folder paths of music files from Android MediaStore for inputted directory path.  So actually question is about how to make proper query to the MediaStore.</p>
  
  <p>Here is an example.
  My current code:</p>
  
  <pre><code>String dirPath="/mnt/sdcard/Music/";
      String selection =MediaStore.Audio.Media.DATA +" like ?";
      String[] projection = {MediaStore.Audio.Media.DATA};    
      String[] selectionArgs={dirPath+"%"};
      Cursor cursor = this.managedQuery(
          MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
          projection,
          selection,
          selectionArgs,
          null);
      List&lt;String&gt; songs = new ArrayList&lt;String&gt;();
      while(cursor.moveToNext())
          songs.add(cursor.getString(0));
  </code></pre>
  
  <p>As a result we’ll have in the <code>songs</code> List smth like: </p>
  
  <pre><code>/mnt/sdcard/Music/song1.mp3
  /mnt/sdcard/Music/song2.mp3
  /mnt/sdcard/Music/FolderWithSongs/song3.mp3
  /mnt/sdcard/Music/AnotherFolderWithSongs/song4.mp3
  /mnt/sdcard/Music/AndOneMoreFolder/song5.mp3
  /mnt/sdcard/Music/AndOneMoreFolder/song6.mp3
  /mnt/sdcard/Music/AndOneMoreFolder/song7.mp3
  /mnt/sdcard/Music/AndOneMoreFolder/SomeFolder/song8.mp3
  /mnt/sdcard/Music/AndOneMoreFolder/SomeFolder/song9.mp3
  </code></pre>
  
  <p>What I’m actually looking for - to get such DISTINCT list of one-level nested paths from <code>dirPath</code> like this:</p>
  
  <pre><code>/mnt/sdcard/Music/FolderWithSongs/ 
  /mnt/sdcard/Music/AnotherFolderWithSongs/ 
  /mnt/sdcard/Music/AndOneMoreFolder/
  </code></pre>
  
  <p>If here will be current folder files - <code>/mnt/sdcard/Music/song1.mp3</code> and
  <code>/mnt/sdcard/Music/song2.mp3</code> – it’s acceptable too.</p>
  
  <p>Any ideas?</p>
  
  <p><strong>EDIT</strong>
  I've found two possible solutions:
  <a href="https://stackoverflow.com/questions/10894576/android-list-music-by-folders-and-play-them">Android list music by folders and play them</a> 
  and <a href="https://stackoverflow.com/questions/1005551/construct-a-tree-structure-from-list-of-string-paths">Construct a tree structure from list of string paths</a>
  , but I think better way to solve this problem is possible.</p>