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

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

4

1 回答 1

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();
于 2010-07-25T08:59:53.810 回答