0
我想製作一個計時器,並讓它在最後播放聲音。我做了定時器,它工作正常,但聲音不會播放。這是我到目前爲止有:定時器到零時如何播放聲音?
int main() {
//cout << "This is a timer. It is still in the making but it the seconds work properly." << endl;
//Sleep(7000);
//system("CLS");
int input;
cout << "Enter a time: ";
cin >> input;
cout << endl << "Begin." << endl;
system("CLS");
while (input != 0) {
input--;
cout << input << " seconds" << endl;
Sleep(200);
system("CLS");
if (input == 0) {
PlaySound(TEXT("C:\\Users\\iD Student\\Downloads\\Never_Gonna_Hit_Those_Notes.wav"), NULL, SND_FILENAME | SND_ASYNC);
}
}
}
您正在以異步模式播放聲音。我猜主要在聲音開始播放之前終止。嘗試刪除'SND_ASYNC'。 – DimChtz
謝謝Dim!刪除'SND_ASYNC'修復了它。 –