[Android] Audio Decoding Issues Discussion

[Android] Audio Decoding Issues Discussion
0.0 0


Solved it, a function was missing and that was causing the lag (getSDKVersion from JNIHelper). Now it works fine in all devices :slight_smile:


Great. :grinning:


I don’t use SimpleAudioEngine at all.
I was wondering if this could be related, for instance if the new AudioEngine used hashmaps as well.
I have no more info on these crahes, I only got them through analytics and had no similar crash on my personal devices…


AudioEngine doesn’t use any java code, it’s implemented in native (cpp). So this crash seems not to be related to AudioEngine.
BTW, could you provide the whole crash stack log? And are you make sure this crash appear in the version of applying my patch?


Here is the stack trace I get:


at java.util.HashMap$HashIterator.nextEntry(HashMap.java:851)
at java.util.HashMap$EntryIterator.next(HashMap.java:891)
at java.util.HashMap$EntryIterator.next(HashMap.java:890)
at org.cocos2dx.lib.Cocos2dxSound.setEffectsVolume(Cocos2dxSound.java:250)
at org.cocos2dx.lib.Cocos2dxHelper.setEffectsVolume(Cocos2dxHelper.java:419)
at org.cocos2dx.lib.Cocos2dxRenderer.nativeRender(Native Method)
at org.cocos2dx.lib.Cocos2dxRenderer.onDrawFrame(Cocos2dxRenderer.java:104)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1553)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1253)


@dumganhar So I am not the only one getting hash map concurrent modification error, please consider above post.

@atin_agarwal2 do you have a way to reproduce this error ? Do you confirm that you are using the new audio engine too ?


Cocos2dxSound is a class used by SimpleAudioEngine, not AudioEngine. AudioEngine uses cpp code only.


I’m sure it’s a different issue which caused by SimpleAudioEngine.
I send a PR for it


@dumganhar Thanks for your effort!!

I´m currently using v3.13.1 How can I merge your changes into this version?
I normally just use the complete download package to update cocos2d.
So I have no idea how to merge your changes using git…

I dont want to use the zip files in post #3 because it seems you made some changes since then.

Can you halp me please?
Thanks in advance!



Basically, you need to

  • clone the source code of v3 branch on github
  • run python download-deps.py
  • copy cocos/audio/android and replace to your project
  • copy external/android-specific to your project
  • re-compile your project

You probably will meet some compilation errors but i think it’s not difficult to fix.
BTW, we will release v3.15 this month.



is the problem with limited max instance of AudioEngine fixed? So it should stop older sounds in order to make “room” for the new ones.

Android bad support

@piotrros, I haven’t enough time for doing this refactor.
There is probably an issue about changing the strategy, that’s, there’s no way to distinguish whether an audio is a background music since we should not remove the room of background music.
Currently, maybe we need to check whether the audio is streaming and streaming audio should not be killed while no more rooms for new audios.


Music should be reserved channel and separate functions to play/stop it.


Yep, yep.
A Pull Request for this issue will be appreciated.


I have try this method.
it’s report a bug.

cocos2d::experimental::AudioEngineImpl::init(),line:157,msg:“create opensl engine fail”

the device is vivo x3sw.
android version is 4.2.2


Engine version?
How did you try ?
Is it reproduced on other android devices?


engine version is 3.15.1
just use
AudioEngine::play2d(“background.mp3”, true,1);
in function
auto result = slCreateEngine(&_engineObject, 0, nullptr, 0, nullptr, nullptr);
so I think this devices is special.
the other devices vivo x5 is ok.


Oops, Vivo sucks. OpenSLES is android standard from Android 2.3.
I think it’s Vivo who removes the module from Android source.
We don’t have a plan to support such non-standard platform.



I have made an obb through zip -r main.1.com.test.game.obb * & then i have put it in internal storage & then when i run the apk on device its sound not working.

I am getting this Error.

E/AudioEngineImpl: Failed to open file descriptor for ‘sounds/piano/fa.mp3’
11-24 17:39:52.615 15269-15295/com.test.game
E/AudioPlayerProvider: Failed to open file descriptor for ‘assets/sounds/piano/fa.mp3’
11-24 17:39:52.615 15269-15295/com.test.game
E/AudioPlayerProvider: File info is invalid, path: assets/sounds/piano/fa.mp3


I am using cocos v 3.16 & ndk r12 android - 15