James Cornod
James Cornod

Reputation: 39

PlaySound does not work

I have a tetris game and I want to add a background music to it. I am trying to use PlaySound(TEXT("Tetris.wav"), NULL, SND_SYNC); but instead of music, I just get "windows sound".

It compiles. I guess it does not want to work with glut.

Here's my 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();
}

I have #include <Windows.h> and #include <MMSystem.h.> included and it works fine here:

#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;
}

So is it because of glut and can I fix it somehow?

Upvotes: 0

Views: 1028

Answers (2)

The problem is probabaly because you have not yet added WINMM.LIB (windows multimedia library) to object libraries that the linker uses. And it is not included by default. If you use VS, you need to go to project setting(properties) and follow this path: Linker->General->Additional Library Directories , and then add the WINMM.LIB to this section. After that you are good to use multimedia function calls.

Upvotes: 0

Andreas Rejbrand
Andreas Rejbrand

Reputation: 109003

First, you'd better use an absolute path.

Second, I would use the SND_FILENAME flag, as described by the official documentation.

(I cannot imagine this having anything to do with GLUT.)

Upvotes: 2

Related Questions