CocosDenshion playBackgroundMusic lag

CocosDenshion playBackgroundMusic lag
0.0 0



Whenever I try to play background music, the game is stuck for a small amount of time. Is there any way to remedy this, like preloading music, or asynchronously loading music before it starts playing? It’s really annoying.


Hey, why don´t you simply preload it with this code. Put it in the AppDelegate.cpp

SimpleAudioEngine::sharedEngine()->playBackgroundMusic("yourFile.ext", true) SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic()

Whenever you want to play it immediately, simply use



That works if you only have one background music file, but not if you have multiple that you switch through like me.






It works for effects, but not for background music. For background music, the “preload” function does absolutely nothing:

From SimpleAudioEngine.cpp:

void SimpleAudioEngine::preloadBackgroundMusic(const char* pszFilePath)
@ @


I would use your background music as effects. Build them into endless audiofiles (there exists several apps) and preload them. Then use
for immediate loading


Unfortunately for a lot of systems that won’t work, because I think for example the SoundPool on android only has 1MB of memory allocated for it…the effects are really only supposed to be short sounds.


Then you need to implement your own preloadBackgroundMusic function. Or if you play the new background music, why don´t you simply show a loadingscreen or something? For what reason do you have different background music files?


Each different “area” of the game has different music, and you go between areas often. I think the problem only occurs on Win32 though, and not Android or iOS, so I think I should be good.


Use effects and use a timer, that reload the effect after maybe 30 secs, so you dont need a big buffer. But btw, i think its np to load maybe 50MB into the RAM, because todays devices have >= 512MB!


I know the devices could probably load a lot of stuff into RAM, but the OS won’t let me.