c++ - PlaySound 不工作

标签 c++ windows audio glut

我有一个俄罗斯方 block 游戏,我想给它添加背景音乐。 我正在尝试使用 PlaySound(TEXT("Tetris.wav"), NULL, SND_SYNC);但是我得到的不是音乐,而是“windows sound”。

它编译。我猜它不想处理过多的问题。

这是我的 main()

int main(int argc, char **argv)
{
    PlaySound(TEXT("Tetris.wav"), NULL, SND_SYNC);
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
    glutInitWindowSize(600,600);
    glutInitWindowPosition(1000, 10);
    glutCreateWindow("Tetris");
    glClearColor(0, 0, 0, 1);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0, 150, 200, 0, -1.0, 1.0);
    glutDisplayFunc(display);
    timer(0);
    glutSpecialFunc(keyEvent);
    glutMainLoop();
}

我有#include <Windows.h>#include <MMSystem.h.>包括在内并且在这里工作正常:

#include <iostream>
#include <Windows.h>
#include <MMSystem.h.>
using namespace std;

int main()
{

    PlaySound(TEXT("Tetris.wav"), NULL, SND_SYNC);
    cout << "Hello world!" << endl;
    return 0;
}

那是因为供过于求吗,我能以某种方式解决它吗?

最佳答案

首先,你最好使用绝对路径。

其次,我将使用 SND_FILENAME 标志,如 the official documentation 所述.

(我无法想象这与 GLUT 有任何关系。)

关于c++ - PlaySound 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49369381/

相关文章:

c++ - 如何在子类构造函数中调用父构造函数?

c++ - Gtkmm 获取标签颜色

c++ - VAO 是否也自动绑定(bind)索引数组?

c++ - 浮点类型作为 C++20 中的模板参数

windows - 在 Windows x64 上使用 RtlAddFunctionTable 描述动态生成的代码

c - 签名 Windows x64 驱动程序 - 系统找不到指定的文件

flash - 播放带有偏移的Flash声音

python - 属性错误 : 'str' object has no attribute 'regex' django 1. 9

node.js - 是否可以编写一个CLI来播放Soundcloud的音乐而无需在浏览器中直观地打开Soundcloud?

objective-c - 对于 iPhone 上的类似卡拉 OK 的应用程序,我应该如何使用音频突出显示文本?