1
나는 10 개 작은에는 OGG 파일을 가지고 있고 나는이 오디오 파일을로드 할 수 SoundPool.load (FileDescriptor에의 FD, 긴 오프셋, 긴 길이, INT 우선 순위)를 사용하고 싶습니다. 나는 몇 가지 코드를 작성했습니다,하지만 난 그것을 실행할 때 오류 메시지가 얻을 :미디어 파일을 저장하는 확장 파일을 사용하는 경우는, ZIP 파일 는 여전히 안드로이드 미디어 재생 호출을 사용할 수 있도록 그 오프셋 및 길이 컨트롤 (예 : MediaPlayer.setDataSource() 및 SoundPool.load()) 을 제공하십시오.
을 "샘플로드 할 수 없습니다 : (null)와"
을 분명히 오디오가 재생되지 않습니다. 다음은 내가 시도한 것입니다.
public class MainActivity extends Activity {
SoundPool sounds;
boolean loaded = false;
int streamID;
int theId;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
System.gc();
setContentView(R.layout.activity_main);
sounds = new SoundPool(10, AudioManager.STREAM_MUSIC,0);
sounds.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
@Override
public void onLoadComplete(SoundPool sp, int sid, int status) {
loaded = true;
}});
loadSounds();
playSound(theID);
}
private void loadSounds() {
AssetFileDescriptor descriptor = null;
try {
descriptor = getFileDescriptor(this, "audio_files/end_credits.ogg");
} catch (Exception e) {
} finally {
if (descriptor != null)
try{descriptor.close();} catch (IOException e) {}
}
theId = sounds.load(descriptor.getFileDescriptor(), descriptor.getStartOffset(), descriptor.getLength(), 1);
}
public static AssetFileDescriptor getFileDescriptor(Context ctx, String path) {
AssetFileDescriptor descriptor = null;
try {
ZipResourceFile zip = APKExpansionSupport.getAPKExpansionZipFile(ctx, 4, -1);
descriptor = zip.getAssetFileDescriptor(path);
} catch (IOException e) {
e.printStackTrace();
}
return descriptor;
}
private void playSound(int soundID){
if(loaded){
streamID = sounds.play(soundID, 1, 1, 1, 0, 1);}
}
}