2010-07-25 4 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

+0

@iep : 추가되었습니다. 응용 프로그램에 대한 자세한 내용은 훨씬 더 좋은 방법 일 수 있습니다. –

관련 문제