마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

soundpool 및 MediaPlayer 재생시 오류 질문

0 추천

soundpool 및  MediaPlayer 재생시 아래와 같이코드를 짰는데요 문제는 처음에는 잘 되다가 

해당페이지를 껏다 켯다 반복하면  소리가 안나오더라구요

E/AudioTrack: AudioFlinger could not create track, status: -12
E/SoundPool: Error creating AudioTrack

오류는 저렇게 뜨고요 찾아봐도 status: -12 에 대해서는 안나온는데 조언좀 부탁드려요

  final int [] sounds;

        final SoundPool soundz = new SoundPool(100, AudioManager.STREAM_MUSIC, 100);//음악파일개수//스트림타입STREAM_MUSIC //음질 기본값 0//
        sounds = new int[10];
        sounds[0] = soundz.load(this, R.raw.keysound, 1);// 현재 화면의 제어권자// 음악 파일 // 우선순위
        sounds[1] = soundz.load(this, R.raw.item5sound, 1);
        sounds[2] = soundz.load(this, R.raw.item23sound, 1);
 
        class userThread extends Thread{
            public void run(){
                switch (soundnum){
                    //키보드소리 1
                    case 0: soundz.play(sounds[0], 0.5f,0.5f,0,0,1);break;
                    case 1: soundz.play(sounds[1], 0.5f,0.5f,0,0,1); break;//아이템 5
                    case 2: soundz.play(sounds[2], 0.5f,0.5f,0,0,1); break;//아이템 23
                
                }

            }
        }

if(musiconoff.equals("1")){soundnum =0;
                    Thread th = new userThread();
                    th.start();
                }
익명사용자 님이 2019년 3월 27일 질문

1개의 답변

0 추천
-12 는 errno.h 에 있는  #define ENOMEM 12  를 의미 합니다.

 AudioTrack 생성 갯수에 한계가 있어  SoundPool 나 MediaPlayer를  생성만 하고 release를 호출 하지 않으면 할당 받지 못 할 경우

이런 에러가 발생합니다.
new SoundPool 로 SoundPool 객체를 생성하기 전에 기존 생성 한 SoundPool 객체가 있을 경우 기존 SoundPool 객체를  release 후 다시 생성하도록 수정 하시는게 좋을 듯 합니다.
익명사용자 님이 2019년 3월 27일 답변
2019년 3월 27일 수정
...