Search code examples
androidaudiococos2d-x

repeat background music after it ends cocos2dx?


In my app for android, i want to play a music in the background throughout until the game quits. The sound is of length 1 min. What i want is that the sound to repeat automatically when the track ends. any idea?

Update I figured out the solution myself. If someone else have the same problem, here is the solution SimpleAudioEngine::sharedEngine()->playBackgroundMusic(std::string(music_file_name)),true);

The true in the end tells if the sound will loop or not. True: sound will repeat once it has ended. False: Will play just once.


Solution

  • CocosDenshion should have a loop parameter that will handle this for you.

    See here for an example

    Make sure you use PlayBackgroundMusic("file", true) for music and playEffect('file') for sounds though; I seem to recall that playBackgroundMusic has the ability to stream an mp3 from disk (whereas effects have to be loaded into RAM first).