Reputation: 942
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.
Upvotes: 0
Views: 1766
Reputation: 157
You can copy paste the .mp3 or .wav file in the resource folder than add the file in project than use this line as follows:
CocosDenshion::SimpleAudioEngine::sharedEngine()->playBackgroundMusic("background-music.wav", true);
and to play sound effect you copy paste the .mp3 file or .wav file in resource folder then add that to project and use this line as follows:
CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("pew-pew.wav");
make sure you write(without the first ")
"#include "SimpleAudioEngine.h"
at the start of file
and include the corresponding libraries.
Regards, Dushyant.
Upvotes: 1
Reputation: 7176
CocosDenshion should have a loop parameter that will handle this for you.
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).
Upvotes: 1