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

发布于 2024-09-11 19:33:17 字数 764 浏览 2 评论 0原文

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没有播放,为什么?

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);

I've traced the above code,there is no error/warning, but 01.mp3 isn't played,why?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清旖 2024-09-18 19:33:17

虽然代码对我来说看起来不错,但请注意 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();

While the code looks fine to me, note that playSound() is asynchronous. If you're exiting directly afterwards, the sound will never have time to play. E.g.:

int main() {
    // ...
    sytem->playSound(FMOD_CHANNEL_FREE, sound, false, &channel);
    // playSound() returns directly, program exits without sound being heard
}

As a quick work-around for testing (and without knowing what your application will be structured like) you could wait for input from the console:

result = system->playSound(FMOD_CHANNEL_FREE, sound, false, &channel);
// ...
std::cout << "Press return to quit." << std::endl;
std::cin.get();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文