개발모음집

Unable to retrieve AudioTrack pointer for write() 에러 본문

Android

Unable to retrieve AudioTrack pointer for write() 에러

void 2017. 6. 10. 11:02

매트로놈 어플


오디오 트랙을 켰다껐다 반복하니 아래와 같은 에러가 발생


id.crafter E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #3
Process:, PID: 6995
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:309)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.IllegalStateException: Unable to retrieve AudioTrack pointer for write()
at android.media.AudioTrack.native_write_byte(Native Method)
at android.media.AudioTrack.write(AudioTrack.java:1761)
at android.media.AudioTrack.write(AudioTrack.java:1704)
at.AudioGenerator.writeSound(AudioGenerator.java:72)
at metronome.Metronome.play(Metronome.java:66)
at MetronomeAsyncTask.doInBackground(TmFragment.java:527)
at MetronomeAsyncTask.doInBackground(TmFragment.java:512)
at android.os.AsyncTask$2.call(AsyncTask.java:295)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)



해결방안은 여기서 

https://stackoverflow.com/questions/23324943/unable-to-retrieve-audiotrack-pointer-for-write


public void destroyAudioTrack() { // 오디오 끄는 역할

if (audioTrack != null && audioTrack.getState() != AudioTrack.STATE_UNINITIALIZED) {
if (audioTrack.getPlayState() != AudioTrack.PLAYSTATE_STOPPED) {
try {
audioTrack.stop(); // 오디오 재생 종료

} catch (IllegalStateException e) {
e.printStackTrace();
}
audioTrack.release(); // 오디오 트랙이 잡은 모든 리소스를 해제시킨다.
}
}
}

}