2013-08-30 1 views
0

나는 내 프로젝트에서 코드의 다음과 같은 세 가지 라인을 가지고 : 런타임시안드로이드 프로젝트에 리소스 파일을 가져올 수없는 이유는 무엇입니까?

String filePathString = "android.resource://"+this.getPackageName()+"/res/raw/oldphone_mono.wav"; 
File f = new File(filePathString); 
if(f.exists()) {/* do something */} 

는 filePathString는 값 android.resource://com.johntestapp/res/raw/oldphone_mono.wav 있습니다. 내 프로젝트에서는 oldphone_mono.wav 파일이 my/res/raw/디렉토리에 있음을 알 수 있습니다. 그러나 어떤 이유로 f.exists()는 여전히 false로 평가됩니다. 내 wav 파일의 경로를 선언하는 방식에 어떤 문제가 있습니까?

+3

'myActivity.getResources(). openRawResource (R.raw.oldphone_mono)' –

답변

2

Do InputStream inputStream = getResources().openRawResource(R.raw.oldphone_mono); 대신.

+0

을 시도한 다음, 결국에는'MediaPlayer p = new MediaPlayer(); p.setDataSource (this, Uri.parse (filePathString));'. FileStream에 inputStream을 변환하는 방법이 있습니까? – John

+0

그 경우 당신이 원하는 것은'MediaPlayer mp = MediaPlayer.create (this, R.raw.oldphone_mono);' – AxiomaticNexus

관련 문제