Intemittent Sound playing problems

Intemittent Sound playing problems
0.0 0


Hi all,
I’m having issues playing sound with SimpleAudioEngine. About 50% of the time it does not play, or only starts to play after about 5 tries, like its taking a while to load the sounds. On the Android platform I’m getting a SoundPool sample not ready error for sounds first played in a scene, but eventually after repeated events it started to play. I’ve tried using preLoadEffect() but it does not seem to have much difference. On the iOS emulator its

Is there a prefered format (codec, samples, rate, bit size, etc).

Should I run the sound in a separate thread? The most problematic sound is when a new scene is being transitioned to.


Please refer to [[Audio formats supported by CocosDenshion on different platforms]], I hope it’s helpful for you.


No, this document does not help me that much. I’ve tried MP3, OGG, WAV without much success. Some scenes are heavy to load, some arent. I can’t seem to find any logic why the sounds take so long to get initialise and play…


You can trace the source code in & The 1st one is for BGM and the 2nd one is for effects.
When playing a short effect, 2dx uses SoundPool; while for BGM 2dx uses MediaPlayer.
On Android, OGG format is recommended.
The defect is that the framework still have no async loading API for BGM and effects.


My solution for the moment is that I’ve added in a small CCDelay before I launch the next scene. seems to give the sound engine a chance to play.


You should preload before you playing it.


Hi I solve this issue by doing this in

             * Someone reports that, it can not play effect for the
             * first time. If you are lucky to meet it. There are two
             * ways to resolve it.
             * 1. Add some delay here. I don't know how long it is, so
             *    I don't add it here.
             * 2. If you use 2.2(API level 8), you can call 
             *    SoundPool.setOnLoadCompleteListener() to play the effect.
             *    Because the method is supported from 2.2, so I can't use
             *    it here.
            //playEffect(path, isLoop);
            this.mSoundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() {
                public void onLoadComplete(SoundPool soundPool, int sampleId, int status)  {
                    if (status == 0)
                        playEffect(path, isLoop);

Is playEffect ok in there like that? I think I might be getting crashes in the sound if there is too many sounds playing at once…



could you please explain a bit more how to integrate OnLoadCompleteListener? (I’m quite unexperienced in Java).
I’m getting “sample X not ready” by trying to play 1 Mb file (preloaded).


it looks like OnLoadCompletedListener is already implemented in my cocos2d-x version. Then any ideas how to debug why I’m still getting “sample not ready”?


You can debug in android java using debug statements like this:

Log.d("apptag", "log statement");

As to why your sound is not preloading, try a smaller file first, to see if that helps