미디어 플레어를 이용한 오디오 재생 프로그램을 작업 중인데요. 서버로 부터 mp3 파일을 다운로드 받은 다음 MediaPlayer를 Prepare할 때 에러가 납니다. 파일탐색기에서 보면 해당 파일은 제대로 다운로드 되어진 상태이구요, 제 PC에 복사한 다음 재생해 보면 정상적으로 동작합니다. 아래는 관련 소스입니다.
public class ViewArticleActivity extends Activity { MediaPlayer mediaPlayer; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView (R.layout.activity_view_article); mediaPlayer = new MediaPlayer(); }
protected void downloadAudio(String url){
HttpDownload download = new HttpDownload(this, new
HttpDownloadListener(){
ProgressDialog mProgress;
public void onStart() {
Resources res = getResources();
mProgress = ProgressDialog.show(ViewArticleActivity.this,
res.getString(R.string.download), res.getString(R.string.wait_download));
}
public void onDone(String filePath) {
mProgress.dismiss();
if (filePath==null){
Log.e(TAG, "File is null");
return;
}
File f = new File(filePath);
if (!f.exists()){
Log.e(TAG, "File not found:" + filePath);
return;
}
try {
//DB Access code will be here
mediaPlayer.setDataSource(filePath);
mediaPlayer.prepare(); //==> Error here
} catch (Exception e) {
Toast.makeText(ViewArticleActivity.this, e.getMessage(), Toast.LENGTH_LONG).show();
}
}
});
download.download(url, "mypackage");
}