2
\$\begingroup\$

I have 2 audio files that I want to play at different times: background.wav a sneeze.wav. I believe that I have to convert both wav files into mp3, caf and ogg files. Then I do this:

static const int FILE_COUNT = 2;
std::string _audioBackgroundFiles[FILE_COUNT];
_audioBackgroundFiles[0] = "background.mp3";
#if CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC
    _audioBackgroundFiles[1] = "background.caf";
#else
    _audioBackgroundFiles[1] = "background.ogg";
#endif

for(int index = 0; index < FILE_COUNT; ++index){
        auto id = AudioEngine::play2d(_files[index], false, 1.0f, &_audioProfile);
}

I don't understand how to create an audio profile? Do you create a profile for every sound? I'm very confused.

\$\endgroup\$
  • \$\begingroup\$ similar issue here with v3.10, I didn't bother to search for a solution because AudioEngine is still in it's experimental phase \$\endgroup\$ – rraallvv Feb 29 '16 at 2:33
1
\$\begingroup\$

This is what I ended up doing:

#include "audio/include/AudioEngine.h"

using namespace cocos2d::experimental;

[...]

_musicVol = 5;
_backgroundAudioProfile = AudioEngine::INVAILD_AUDIO_ID;

if (_backgroundAudioProfile == AudioEngine::INVAILD_AUDIO_ID) {
    _backgroundAudioProfile = AudioEngine::play2d("background.mp3", true, _musicVol);
}

AudioEngine::pause(_backgroundAudioProfile);
| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.