gpt4 book ai didi

c++ - PlaySound() mmslib 不播放现有声音

转载 作者:可可西里 更新时间:2023-11-01 10:39:33 28 4
gpt4 key购买 nike

编辑:已解决。 Windows 不接受 .wav 文件。我提取了一个 Windows 自己的文件并将其重命名为我以前的文件的名称,并且播放没有问题。

我不知道为什么这不能播放现有文件。 Windows 提示有问题,但我不知道是什么。

我之前添加了一个检查以确保它存在。我也试过绝对路径。

string wavPath = "c:\\frog.wav";

struct stat stFileInfo;
bool blnReturn = (stat(wavPath.c_str(), &stFileInfo) == 0); //this returns true

FILE* fp = fopen(wavPath.c_str(), "r");
if (fp) {
fclose(fp); //this triggers
}

PlaySound(wavPath.c_str(), NULL, SND_FILENAME | SND_ASYNC); //m_hinstance
//C:\\Users\\Wollan\\My Code\\A\\Debug\\frog.wav
//TEXT("frog.wav")
//TEXT(wavPath.c_str())
//(LPCSTR)"frog.wav¨

该文件在 WMP 中播放良好。

最佳答案

以下代码完美运行:

PlaySound(L"C:\\Windows\\Media\\Cityscape\\Windows Balloon.wav", 0, SND_FILENAME ); 

添加SND_ASYNC播放失败

关于c++ - PlaySound() mmslib 不播放现有声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6823955/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com