SPRING :: NOTE

[ANDROID] SoundPool 사용 및 재생 안될 때, 해결 방법 본문

Development Language/JAVA · ANDROID

[ANDROID] SoundPool 사용 및 재생 안될 때, 해결 방법

RAYZIE 2020. 3. 10. 16:30
반응형

안드로이드 개발 중, 간단한 알림음이 필요하여 SoundPool을 구현

SoundPool sp = new SoundPool(1,         // 최대 음악파일의 개수
                AudioManager.STREAM_MUSIC, // 스트림 타입
                0);        // 음질 - 기본값:0

        // 각각의 재생하고자하는 음악을 미리 준비한다
        int soundID = sp.load(_context, // 현재 화면의 제어권자
                R.raw.alert,    // 음악 파일
                1);        // 우선순위


        sp.play(soundID, // 준비한 soundID
                1,         // 왼쪽 볼륨 float 0.0(작은소리)~1.0(큰소리)
                1,         // 오른쪽볼륨 float
                0,         // 우선순위 int
                0,     // 반복회수 int -1:무한반복, 0:반복안함
                0.5f);    // 재생속도 float 0.5(절반속도)~2.0(2배속)

 

위와 같이 했는데, 재생이 안될 때 아래와 같이 소스코드를 play 함수 밑에 입력해준다.

Error : WARN/SoundPool(644):   sample 1 not READY
// SoundPool 소리 안날 때 해결 방법
// 출처 : https://www.androidpub.com/1228909
int waitLimit = 1000;
int waitCounter = 0;
int throttle = 10;
while(sp.play(soundID, 1.f, 1.f, 1, 0, 1.f) == 0 && waitCounter < waitLimit){
}
반응형
Comments