我的问题如下。我用 Playsound() 函数播放声音没有问题,但是如果程序找不到合适的声音文件(因为它不存在),我想打印“文件不存在”sencence 而不是程序播放默认“bip”语音。如果 Playsound() 的播放不成功,有什么方法可以获取值。从理论上讲,如果成功则返回 TRUE,否则返回 FALSE,但我无法用变量捕获它们。我用 C 编程并使用 DevC++ 4.9.9.2 和 CodeBlocks 12.11 没有任何成功。
感谢任何帮助!
My Codes:
//Try_1:
#include <stdio.h>
#include <windows.h>
main()
{
//if (!PlaySound("R2D2.wav",NULL, SND_FILENAME )) // not working
if (!PlaySound("R2D2.wav",NULL, SND_FILENAME | SND_NODEFAULT | SND_ASYNC)) // not working properly
{
printf("The file is not exist");
}
system("pause");
}
/*
If the program can't find the R2D2.wav then there isn't the default "bip" voice thanks to the SND_NODEFAULT, but the printf line will not run so I don't see the "The file is not exist" sentence.
*/
//--------------------------------------------------------------------
//Try_2:
#include <stdbool.h>
#include <stdio.h>
#include <windows.h>
main()
{
//Returns TRUE if successful or FALSE otherwise.
bool x;
x=PlaySound("R2D2.wav",NULL, SND_FILENAME | SND_NODEFAULT | SND_ASYNC); // not working properly
if (x==FALSE)
{
printf("The file is not exist");
}
system("pause");
}
/*
If the program can't find the R2D2.wav then there isn't the default "bip" voice thanks to the SND_NODEFAULT, but the printf line will not run, so I don't see the "The file is not exist" sentence.
*/