Android 2.2 - SoundPool示例0未准备就绪

时间:2011-10-16 18:20:42

标签: android soundpool

我搜索过StackOverflow并且找不到像我这样的情况。我使用四个按钮,每个按钮播放声音文件 我正在使用SoundPool:
      SoundPool sound = new SoundPool(4, AudioManager.STREAM_MUSIC, 0);

我也在使用OnLoadCompleteListener()使用Log在LogCat中创建I通知 当我在模拟器中启动程序时,我看到所有四个样本都完成加载。在节目中,将播放三个声音,然而,总会说: WARN/SoundPool(4842): sample 0 not READY

任何想法..因为我非常惊讶。声音文件是播放方波音的16位pcm波形文件 加载代码:
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);

@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);
播放声音:

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

1 个答案:

答案 0 :(得分:2)

我遇到了同样的问题。根据我的实验,看起来ID处理有问题。 SoundPool只是不喜欢数字为0的声音ID。

所以我找到了解决办法。用1开始我的样本ID,而不是0.希望这样做。