나는 응용 프로그램을 개발하고있어 그 응용 프로그램에서 하나의 버튼을 '소리를 선택하십시오. 사용자가이 버튼을 클릭하면 파일 관리자/메모리에서 오디오 파일을 선택하라는 메시지를 표시해야합니다.안드로이드 어떻게 sdcard/파일 관리자에서 오디오 파일을로드하고 그것을 재생
그래서, 나는 이것을 알고, Intent.Action_GetData
을 사용해야 할 것입니다.
//code start
Intent intent = new Intent();
intent.setType("audio/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(intent,1);
@Override
protected void onActivityResult(int requestCode,int resultCode,Intent data){
if(requestCode == 1){
if(resultCode == RESULT_OK){
//the selected audio.
Uri uri = data.getData();
int SoundID=soundPool.Load(uri.toString(), 1);
//SoundPool is already constructed and is working perfectly for the resource files
PlaySound(SoundID);
//PlaySound method is already defined
}
}
super.onActivityResult(requestCode, resultCode, data);
}
//end of code
을하지만 Android 4.4
하기 전에, 그것은 반환하기 때문에, 내가 어떻게 사용자가 선택한 파일의 적절한 URI를로드 할 것을받지 못했습니다 OnActivityResult
에 지금
을 작동하지 않습니다 : 나도 같은 일을 해요 다른 URI와 Android 4.4
이후에 intent.GetData();
에 다른 URI를 반환합니다. 자, 내가해야 할 일은?
또한 오디오 파일을 재생할 때 SoundPool
을 사용해야한다는 것을 알고 있습니다. 실제로 코드는 리소스/원시 파일/오디오 파일에 잘 적용되지만로드하는 방법은 있습니다./SoundPool
에있는 파일을이 URI
에서 재생 하시겠습니까?
'OnActivityResult'에서 수행 한 코드를 게시 할 수 있습니까? 그리고 어떻게'URI'를 얻고 있습니까? –
@Prathamesh Toradmal이 코드 –