为什么 playSound 实际上在 Windows 上使用 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
没有播放,为什么?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
虽然代码对我来说看起来不错,但请注意
playSound()
是异步的。如果您随后直接退出,则声音将永远没有时间播放。例如:作为测试的快速解决方法(并且不知道您的应用程序的结构如何),您可以等待来自控制台的输入:
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.: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: