简体   繁体   English

我应该使用哪种音频格式在android上编译cocos2d?

[英]What audio format should I use to compile cocos2d on android?

When i run my cocos2d game on iphone the only sound file that work is .caf 当我在iPhone上运行cocos2d游戏时,唯一起作用的声音文件是.caf

But in android i was try with .mp3 .ogg .aac .wav, and no one of these is working. 但是在android中,我尝试使用.mp3 .ogg .aac .wav,但是这些都没有起作用。

i'm testing on android 4.4 and 5.0 我正在android 4.4和5.0上进行测试

With what sound file does cocos2d-x 3.3 work on android? cocos2d-x 3.3在Android上可以使用什么声音文件? Or what change can I make in my code? 或者我可以对代码进行哪些更改?

#include <SimpleAudioEngine.h>
bool HelloWorld::init()
{

auto audio = CocosDenshion::SimpleAudioEngine::getInstance();

audio->preloadBackgroundMusic("FunTime.mp3");
audio->setBackgroundMusicVolume(5.0f);

audio->playBackgroundMusic("FunTime.mp3", true);


}

Try using AudioEngine instead of SimpleAudioEngine. 尝试使用AudioEngine代替SimpleAudioEngine。 It works perfectly fine with mp3. 它与mp3完美搭配。

Example: 例:

#include <AudioEngine.h>

bool HelloWorld::init()   {
cocos2d::experimental::AudioEngine::play2d("FunTime.mp3" ,true,5.0f);
}

You can also preload the audio if you want. 您也可以根据需要预加载音频。 Hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM