Hi, because SimpleAudioEngine is too simple for my app I was forced to use AudioEngine. I’m fully aware it’s in experimental package. However everything works except one bug, which happens occasionally. It happens when some sounds are playing and I switch scene. In destructor I’m calling
cocos2d::experimental::AudioEngine::uncache to free memory. Usually it works, but sometimes I’m getting following crash:
I tried stopping sounds before uncaching like this:
setonExitTransitionDidStartCallback([&](){
cocos2d::experimental::AudioEngine::stopAll();
});
Yet it’s still happening.
When I remove uncache method from destructor it’s no longer crashing, but I can’t free memory.
How can I fix this?
Stabbing in the dark here. Try calling uncache on the line before you switch scenes. The destructor of your scene may not be a safe time to call it.
Just tried it doesn’t work
There’s sometimes different crash on some custom thread too and I personally think it’s some problem with async threads, which are used in AudioEngine.
Solved it different way!
I’ve added needed methods to SimpleAudioEngine. However I couldn’t add them all (only setVolume) for android, because it’s using soundpool which doesn’t support it.
For iOS I got these working with SimpleAudioEngine:
virtual void setEffectVolume(unsigned int soundId, float volume);
virtual bool isEffectPlaying(unsigned int soundId);
virtual float getEffectVolume(unsigned int soundId);
virtual void seekEffect(unsigned int soundId, float seconds);
virtual float getEffectDuration(unsigned int soundId);
virtual float getEffectPosition(unsigned int soundId);
For android we can use AudioEngine (experimental). As far as I know only getDuration doesn’t work to me (it returns -1) just after played sound. But it works 3 updates later 