2010-07-25 43 views
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没有播放,为什么?为什么playSound实际上在Windows上使用FMOD输出任何声音?

回答

1

尽管代码对我来说很好,但请注意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(); 
+0

有没有解决办法? – ieplugin 2010-07-25 11:22:21

+0

@iep:已添加。有关您的应用程序的更多细节可能有更好的方法。 – 2010-07-25 11:47:05

相关问题