Playing background music and sound effects using experimental::AudioEngine
At cocos2d-x version 3.3 experimental::AudioEngine was introduced and multiple background scores can be played.
In addition to that, AudioEngine can call a callback function when it finishes playing a background music.
AudioEngine does not distinguish between background music and sound effects and just use same API.
#include "audio/include/AudioEngine.h"
USING_NS_CC;
using namespace experimental;
// play background music
int id= AudioEngine::play2d("bg.mp3");
// set loop
AudioEngine::setLoop(id, true);
// change volume
AudioEngine::setVolume(id, .5f);
// pause
AudioEngine::pause(id);
// resume
AudioEngine::resume(id);
// stop
AudioEngine::stop(id);
// seek it by specifying the time
AudioEngine::setCurrentTime(id, 12.3f);
// set callback when finished
AudioEngine::setFinishCallback(id, [](int audioId, std::string filePath) {
// callback function body
});