2017-02-24 78 views
1

我想从特定文件夹中获取mp3文件的列表。MediaStore从特定路径列出

截至目前,我正在使用contentResolver.query从手机获取音乐。

像这样:

String selection = MediaStore.Audio.Media.IS_MUSIC + " != 0"; 

     String[] projection = { 
       MediaStore.Audio.Media._ID, 
       MediaStore.Audio.Media.ARTIST, 
       MediaStore.Audio.Media.TITLE, 
       MediaStore.Audio.Media.DATA, 
       MediaStore.Audio.Media.DISPLAY_NAME, 
       MediaStore.Audio.Media.DURATION 
     }; 

     ContentResolver contentResolver = context.getContentResolver(); 
     cursor = contentResolver.query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,projection, selection,null,null); 

我要寻找的解决方案只扫描特定文件夹。我如何使用contentResolver来做到这一点?

谢谢!

+0

这个http://stackoverflow.com/questions/20852271/using-contentresolver-and-regex-to-get-音乐从特定的文件夹 –

回答

2

终于明白了我自己。希望它能帮助别人。

取而代之的是:

cursor = contentResolver.query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, projection, selection, null, null); 

我用这个:

cursor = contentResolver.query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, projection,MediaStore.Audio.Media.DATA + " like ? ", 
       new String[] {"%MyMusicFolder%"}, null);