2014-09-05 2 views
2

특정 폴더의 모든 MP3 파일 목록을 가져 오는 방법은 무엇입니까?특정 폴더의 MP3 파일 목록 - Android

내 폴더

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

이 다음 코드 쇼는 내가 목록을 가져올 내 폴더에만

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

+0

이것을 확인하십시오 : http://stackoverflow.com/questions/17210519/how-to-access-all-mp3-files-from-all-the-subfolders-in-the-sdcard – kedark

+0

예, 작동하지만 저는 모릅니다. 내 코드로 할 ... – Mullinsangebn

답변

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입니다 원하는 폴더의 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

+0

선생님, 제 코드를 확인해 주시겠습니까? – Mullinsangebn

관련 문제