2013-12-13 5 views
0

나는 노래가 들어있는 음악 앨범 앱을 만들려고하고있다. 나는 플레이어를 만들었지 만 플레이어가 SD 카드의 특별한 주소에서 음악을 사용하고 오디오를 복사하거나 장치에 설치된 설치된 자산 (또는 행) 폴더를 사용해야하기 때문에 멈추었습니다. 휴대 전화의 메모리에이 폴더가 있는지 여부). 더 좋은 방법이 있으면 알려주세요. 여기 원시 또는 자산 폴더의 오디오를 sdcard에 저장하거나 앱의 설치 주소를 사용하여 액세스하는 방법은 무엇입니까?

내 코드입니다 :

public class SongsManager { 
    // SDCard Path 
    final String MEDIA_PATH = new String("/sdcard/piano/"); 
    private ArrayList<HashMap<String, String>> songsList = new ArrayList<HashMap<String, String>>(); 

    // Constructor 
    public SongsManager(){ 

    } 

    /** 
    * Function to read all mp3 files from sdcard 
    * and store the details in ArrayList 
    * */ 
    public ArrayList<HashMap<String, String>> getPlayList(){ 
     File home = new File(MEDIA_PATH); 

     if (home.listFiles(new FileExtensionFilter()).length > 0) { 
      for (File file : home.listFiles(new FileExtensionFilter())) { 
       HashMap<String, String> song = new HashMap<String, String>(); 
       song.put("songTitle", file.getName().substring(0, (file.getName().length() - 4))); 
       song.put("songPath", file.getPath()); 

       // Adding each song to SongList 
       songsList.add(song); 
      } 
     } 
     // return songs list array 
     return songsList; 
    } 

답변

0

자산 폴더는 사용자가 작성이나 자산 폴더에 SD 카드에서 파일을 저장 할 수없는 읽을 수있는 폴더입니다. 프로젝트의 최종 빌드를 준비하기 전에 초기에 자산 폴더에 일부 MP3 파일을 추가하고 나중에 SD 카드에 복사 할 수 있습니다.

이제 SD 카드 또는 애셋에서이 파일에 액세스 할 수 있습니다. 일부 RESTful POST 웹 서비스 만 사용하여 SD 카드의 MP3 곡을 서버에 저장할 수 있습니다. 여기

How to copy files from 'assets' folder to sdcard?

가 내 문제가 노래/SDCARD/피아노를 형성로드 선수에게

+0

링크를 이용해 주셔서 감사합니다. – Sam

0

폴더가 존재하면 확인할 수 있습니다 : 당신은 자산의 주소를 표시하지 않으

File myFile = new File(myPath); 
if (myFile.exists()) { 
    // The folder exists so use the files in this folder 
} else { 
    // The folder does not exist so use the assets from the apps raw folder 
} 

<Additional>

폴더 (사용자에게 앱의 내부 파일 구조를 나열하는 것은 좋지 않을 것입니다.)하지만 네, 원시 디렉토리에서 파일을 나열 할 수 있습니다 앱에서 선택하고 사용자가 선택할 수 있도록 허용합니다. 다음 코드는 배열 원시 폴더의 내용에서 soundNames[]soundIds[]을 채 웁니다 :

Field[] fields = R.raw.class.getFields(); 
String[] soundNames = new String[fields.length]; 
int[] soundIds = new int[fields.length]; 
for (int i = 0; i < fields.length; i++) { 
    soundNames[i] = fields[i].getName(); 
    soundIds[i] = getResources().getIdentifier(soundNames[i], null, null); 
} 
+0

도움이 될 것입니다 희망 /하지만 내가 원하는 SD 카드에 자산의 파일을 복사 할 수있는 링크입니다 자산 폴더 (내 설치 위치)의 주소를 표시 할 수 있습니까? – Sam

+0

'원시'폴더의 내용 목록을 가져 오는 방법을 보여주기 위해 답변을 업데이트했습니다. –

관련 문제