Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

CocosDenshion Android - missing sound effects with some conditions

Android SoundPool.load returns 0 if sound might not be loaded - for
example, it does not exist. Previously - 0 has been ignored and
incorrectly written to HashMap, so it was not possible to
understand on the application side that something goes wrong
(and use some additional workaround).

Use case:
1) On the game loading - preload all possible sound effects
   (to speed up their playing later, when it will be needed)
2) Game APK does not have any sound file, they are downloaded
   later in a separate thread.
3) Application tries to play sound effects as usual, when needed.

So due to this bug - as there was no any sound file exist
during the game loading - internal HashMap contains incorrect
0 as id for every effect, and there is no any sound effect during
the first application start.
  • Loading branch information...
1 parent 5ca1575 commit 98b5f662ffce2a1641117fca2572d83564c0a298 @mingulov committed
10 cocos2dx/platform/android/java/src/org/cocos2dx/lib/
@@ -108,7 +108,10 @@ public int preloadEffect(final String pPath) {
if (soundID == null) {
soundID = this.createSoundIDFromAsset(pPath);
- this.mPathSoundIDMap.put(pPath, soundID);
+ // save value just in case if file is really loaded
+ if (soundID != Cocos2dxSound.INVALID_SOUND_ID) {
+ this.mPathSoundIDMap.put(pPath, soundID);
+ }
return soundID;
@@ -272,6 +275,11 @@ public int createSoundIDFromAsset(final String pPath) {
Log.e(Cocos2dxSound.TAG, "error: " + e.getMessage(), e);
+ // mSoundPool.load returns 0 if something goes wrong, for example a file does not exist
+ if (soundID == 0) {
+ soundID = Cocos2dxSound.INVALID_SOUND_ID;
+ }
return soundID;

0 comments on commit 98b5f66

Please sign in to comment.
Something went wrong with that request. Please try again.