开发者

WARN/SoundPool sample 2 not READY

开发者 https://www.devze.com 2022-12-17 23:50 出处:网络
SoundPool works properly o开发者_运维百科n Android 1.6 but when I run on 2.1 in the Emulator I am getting a \"sample 2 not READY\" error message everytime I try to play a sound.

SoundPool works properly o开发者_运维百科n Android 1.6 but when I run on 2.1 in the Emulator I am getting a "sample 2 not READY" error message everytime I try to play a sound.

How do I fix this?


SoundPool on Android 2.0 and higher works only with OGG Vorbis files. If you're using MP3 or the like, they won't decode.


On my device just wait a few seconds for the audio stream to be ready.

Or use this, OnLoadCompleteListener: http://developer.android.com/reference/android/media/SoundPool.OnLoadCompleteListener.html

I can play ogg/wav/mp3...

SoundPool can create different decoders/players for each media type.


Here is the code

public void loadSound (String strSound, int stream) {
     boolean loaded = false;
     mSoundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() {
            @Override
            public void onLoadComplete(SoundPool soundPool, int sampleId,
                    int status) {
                mSoundPool.play(stream, streamVolume, streamVolume, 1, LOOP_1_TIME, 1f);
            }
        });
    try {
          stream= mSoundPool.load(aMan.openFd(strSound), 1);
        } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号