FMOD_RESULT result;
FMOD::System *system;
result = FMOD::System_Create(&system);
if (result != FMOD_OK)
{
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
}
result = system->init(100, FMOD_INIT_NORMAL, 0);
if (result != FMOD_OK)
{
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
}
FMOD::Sound *sound;
result = system->createSound("01.mp3", FMOD_DEFAULT, 0, &sound); // FMOD_DEFAULT uses the defaults. These are the same as FMOD_LOOP_OFF | FMOD_2D | FMOD_HARDWARE.
ERRCHECK(result);
FMOD::Channel *channel;
result = system->playSound(FMOD_CHANNEL_FREE, sound, false, &channel);
ERRCHECK(result);
我跟踪了上面的代码,没有错误/警告,但是没有播放01.mp3
,为什么?
最佳答案
虽然代码对我来说看起来不错,但请注意 playSound()
是异步的。如果您之后直接退出,声音将永远没有时间播放。例如:
int main() {
// ...
sytem->playSound(FMOD_CHANNEL_FREE, sound, false, &channel);
// playSound() returns directly, program exits without sound being heard
}
作为测试的快速解决方法(并且不知道您的应用程序的结构),您可以等待来自控制台的输入:
result = system->playSound(FMOD_CHANNEL_FREE, sound, false, &channel);
// ...
std::cout << "Press return to quit." << std::endl;
std::cin.get();
关于c++ - 为什么 playSound 在 Windows 上使用 FMOD 实际上不输出任何声音?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3328593/