Just wondering if anyone else has experienced when too many sounds are playing, then others stop. For example, I have a scene where I have a sound playing for 10 seconds…if I play lots of sounds in between this 10 second window, the sounds stops. Seems to happen on all IOS devices. I am using Cocos2dx version 3.6 SDK
As far as I remember there’s a bug in SimpleAudioEngine on iOS which causes that. I had 3 looped-sounds playing all the time and sound random sounds playing time-to-time. After a while looped-sounds stopped. It’s because function checking for free channel isn’t working as intended.
In CocosDension::playSound try adding this loop between
int sourceIndex = [self _getSourceIndexForSourceGroup:sourceGroupId];//This method ensures sourceIndex is valid
and
if (sourceIndex != CD_NO_SOURCE) {
Here’s a fix:
for(int i = 0; i < sourceTotal_; i++){
ALint state;
ALuint source = _sources[i].sourceId;
alGetSourcei(source, AL_SOURCE_STATE, &state);
if (state != AL_PLAYING && state != AL_PAUSED) {
sourceIndex = i;
break;
}
}
So, you have 32 channels which you can use. Any looped sound should never stop by playing another sound.
I can imagine it being a time pit, especially looking at the IOS code and changing it. Well, you saved me a great pain, and I thank you for that. Have a great week. You deserve it