2014-09-05 97 views
2

我如何從特定文件夾獲取所有Mp3文件的列表?來自特定文件夾的Mp3文件列表 - Android

我的文件夾是

FILE_PATH = Environment.getExternalStorageDirectory().getPath() + "/my folder/" 

這下面的代碼顯示所有文件夾中所有MP3 ..我想從我的文件夾只有

Cursor createCursor(String filter) { 
    ArrayList<String> args = new ArrayList<String>(); 
    String selection; 

    if (mShowAll) { 
     selection = "(_DATA LIKE ?)"; 
     args.add("%"); 
    } else { 
     selection = "("; 
     for (String extension : CheapSoundFile.getSupportedExtensions()) { 
      args.add("%." + extension); 
      if (selection.length() > 1) { 
       selection += " OR "; 
      } 
      selection += "(_DATA LIKE ?)"; 
      selection = selection + "AND (IS_MUSIC=1)"; 
     } 
     selection += ")"; 

     selection = "(" + selection + ") AND (_DATA NOT LIKE ?)"; 
     args.add("%espeak-data/scratch%"); 
    } 

    if (filter != null && filter.length() > 0) { 
     filter = "%" + filter + "%"; 
     selection = 
      "(" + selection + " AND " + 
      "((TITLE LIKE ?) OR (ARTIST LIKE ?) OR (ALBUM LIKE ?)))"; 
     args.add(filter); 
     args.add(filter); 
     args.add(filter); 
    } 
+0

任何一個?可以幫我? – Mullinsangebn 2014-09-05 11:58:55

+0

檢查此:http://stackoverflow.com/questions/17210519/how-to-access-all-mp3-files-from-all-the-subfolders-in-the-sdcard – kedark 2014-09-05 17:50:08

+0

是的,但我不知道如何與我的代碼... – Mullinsangebn 2014-09-06 10:14:07

回答

0

這一個是工作正常

Cursor createCursor(String filter) { 
    ArrayList<String> args = new ArrayList<String>(); 
    String path = Environment.getExternalStorageDirectory().getPath(); 

    String selection = MediaStore.Audio.Media.IS_MUSIC + " !=" + 0 
      + " AND " + MediaStore.Audio.Media.DATA + " LIKE '" + path 
      + "/Fast Mp3 Downloader/%'"; 



    if (filter != null && filter.length() > 0) { 
     filter = "%" + filter + "%"; 
     selection = 
      "(" + selection + " AND " + 
      "((TITLE LIKE ?) OR (ARTIST LIKE ?) OR (ALBUM LIKE ?)))"; 
     args.add(filter); 
     args.add(filter); 
     args.add(filter); 
    } 

    String[] argsArray = args.toArray(new String[args.size()]); 

    getExternalAudioCursor(selection, argsArray); 
    getInternalAudioCursor(selection, argsArray); 

    Cursor c = new MergeCursor(new Cursor[] { 
      getExternalAudioCursor(selection, argsArray), 
      getInternalAudioCursor(selection, argsArray)}); 
    startManagingCursor(c); 
    return c; 
} 
2

使用下面的代碼母豬MP3拿到名單從所需的文件夾的MP3文件: -

private ArrayList<String> listmp3 = new ArrayList<String>(); 
    String[] extensions = { "mp3" }; 

    private void loadmp3(String YourFolderPath) { 

     File file = new File(YourFolderPath); 
     if (file.isDirectory()) { 
      File[] files = file.listFiles(); 
      if (files != null && files.length > 0) { 
       for (File f : files) { 
        if (f.isDirectory()) { 
         loadmp3(f.getAbsolutePath()); 
        } else { 
         for (int i = 0; i < extensions.length; i++) { 
          if (f.getAbsolutePath().endsWith(extensions[i])) { 
           listmp3.add(f.getAbsolutePath()); 
          } 
         } 
        } 
       } 
      } 
     } 

    } 
+0

好的..你能告訴我如何在我的代碼中使用? – Mullinsangebn 2014-09-06 08:12:03

+0

先生,你能檢查我的代碼嗎? – Mullinsangebn 2014-09-06 13:22:11

相關問題