Android 2.2 - SoundPool sample 0 is not READY

女生的网名这么多〃 提交于 2019-12-07 05:21:45

问题


I have searched StackOverflow and cannot find a situtation like mine. I am using four buttons with each button playing a sound file.
I am using SoundPool:
SoundPool sound = new SoundPool(4, AudioManager.STREAM_MUSIC, 0);

I am also using the OnLoadCompleteListener() which uses Log to create an I notification in LogCat.
When I launch the program in the emulator I see all four samples complete loading. During the program three of the sounds will play, however, one will always say:
WARN/SoundPool(4842): sample 0 not READY

Any Ideas.. cause i'm quite flabbergasted. The sound files are 16-bit pcm wave file playing squarewave tones.
Load Code:
sound.setOnLoadCompleteListener(new OnLoadCompleteListener(){

        @Override
        public void onLoadComplete(SoundPool sound, int sampleId, int status) {
            if(status != 0)
                Log.e("SOUND LOAD"," Sound ID: " + sampleId + " Failed to load.");
            else
                Log.i("SOUND LOAD"," Sound ID: " + sampleId + " loaded.");
        }
    });

    soundID[0] = sound.load(this, R.raw.greennote, 1);
    soundID[1] = sound.load(this, R.raw.rednote, 1);
    soundID[2] = sound.load(this, R.raw.yellownote, 1);
    soundID[3] = sound.load(this, R.raw.bluenote, 1);


Play Sound:

streamid.setStreamId(myActivity.sound.play(id, 0.5f, 0.5f, 0, 0, 1));


回答1:


I'm having the same issues. From my experiments, it looks like there's something wrong with the ID handling. SoundPool just doesn't like sound IDs with the number 0.

So I have found a work-around. Start my sample IDs with 1, not 0. Hope this works.



来源:https://stackoverflow.com/questions/7786314/android-2-2-soundpool-sample-0-is-not-ready

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!