c++ - 为什么 playSound 在 Windows 上使用 FMOD 实际上不输出任何声音?

标签 c++ mp3 fmod

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/

相关文章:

python - discord.py [mp3 @ 000001dc99bec540] 从比特率估计持续时间,这可能不准确

linux - 如何用 sed 替换未知字符 <?> ?

c++ - 使用 Visual Studio 11 RC 调试时未找到 DLL 依赖项

audio - FMOD 环绕声开放框架

c++ - 如果 Stack 是使用 Vector 实现的,我应该在 Stack 类析构函数中放入什么?

c++ - c++中没有名字的默认参数

mp3 - Chromium嵌入式框架MP3支持

c++ - 如何同时播放两个或多个声音

c++ - make_tuple 的构建问题 - 数组引用

C++ 向量化 vector 的 vector