2014-02-27 4 views
0

나는 mp3 파일을 재생하는 간단한 응용 프로그램을 만들고 있습니다. 나는 코드를Media Player가 다른 폴더의 경로를 설정했습니다.

mp = MediaPlayer.create(MainActivity.this, R.raw.mysong); 

를 사용하지만이 내 노래는 내 PC의 res\raw 폴더에 저장되어있는 경우에만 작동합니다. 조만간 나는 내 아이폰 앱을 돌릴 것이다. (내가 사 자마자!). 모바일이 저장되는 경로를 설정해야한다면 어떻게됩니까? 내 휴대 전화에서 내 다운로드 폴더를 보자.

답변

0

당신은

mp = MediaPlayer.create(MainActivity.this, Uri.parse(Environment.getExternalStorageDirectory().getPath()+ "/Music/mysong.mp3")); 

또는 사용 setDataSource() 방법 때라도로에게 ExternalStorage에서 그것의 절대 경로를 제공하여 작업을 수행 할 수 있습니다 도움을

String PATH_TO_FILE = "/sdcard/music.mp3";  
mediaPlayer = new MediaPlayer(); 
mediaPlayer.setDataSource(PATH_TO_FILE); 
mediaPlayer.prepare(); 
mediaPlayer.start() 
+0

감사합니다. 내가 무엇을 준비할까요? "유효한 상태에서이 메서드를 성공적으로 호출하면 개체가 Prepared 상태로 전송되고,이 메서드를 잘못된 상태로 호출하면 IllegalStateException이 throw됩니다." 그러나 이것을 이해하는 데 약간 어려움이 있습니다. 어쨌든 고마워요. –

0
String filePath = "somepath/somefile.mp3"; 

MediaPlayer mediaPlayer = new MediaPlayer(); 
mediaPlayer.setDataSource(filePath); 
mediaPlayer.prepare(); 
관련 문제