안드로이드 개발 질문/답변
(글 수 45,052)
public static void PlayMP3() {
if (new File(pathinlocal+FileName).exists() == true) {
MediaPlayer mMediaPlayer = new MediaPlayer();
mMediaPlayer.setDataSource(pathinlocal+FileName); ----Unhandled IO Exception
mMediaPlayer.prepare(); --- Unhandled IOException
mMediaPlayer.start();
mMediaPlayer.release();
}
}
인터넷에서 다운 받아.. /data/.../files 폴더에 mp3 가 저장된 것 까지는 확인했습니다 DDMS - File Explorer 에서요.
하지만, 위의 두 줄에서 오류가 발생해서 실행조차 못하고 있습니다.
pathinlocal 은 /data/...../files 를 담고 있는 string
filename 은 런타임시에 다운받은 파일에 따라 변경되는 string
왜 컴파일 시점에서.... 에러가 날까요? Unhandled......IO Exception 이렇게요.
2010.06.08 23:18:10
MediaPlayer mediaPlayer = new MediaPlayer();
try {
mediaPlayer.setDataSource(path+FileName);
mediaPlayer.prepare();
} catch (IllegalArgumentException e) {
// handle exception
findViewById(R.id.txtV)).setText("IllegalArg");
} catch (IllegalStateException e) {
// handle exception
findViewById(R.id.txtV)).setText("IlegalState");
} catch (IOException e) {
// handle exception
findViewById(R.id.txtV)).setText("IOException");
}
mediaPlayer.start();위와 같이 하더라도 IOException 이 발생합니다.
if (new File(path+FileName).exists() == true) {로 path + filename 을 확인해 봐도 파일은 존재하는것으로 나옵니다.
그리고 위에 setDataSource 에서 /data/data/...../files/aa.mp3
가 아닌 URL 에 있는 mp3 를 할 경우에는 정상적으로 잘 플레이됩니다.
로컬 파일만 재생이 안되네요.
퍼미션 문제인것 같아... 안드라이드 공식 웹문서를 봐도...WAKE_LOCK 만 있던데...
그래도 결과는 IOException 에러 그대로 변함이 없네요..
지금까지...구글링과 여기 게시판 검색으로....코딩 잘하다가...이 부분에 딱 막히네요.
도움 좀 부탁해요~~~




에러내용 그대로 setDataSource(~~) 랑 prepare() 에 예외처리를 안해주셔서 그렇습니다.
두개 메소드를 try catch 로 예외처리를 해주세요.