mercredi 29 juin 2016

PlaySound() function won't play sound

First question, sorry if I don't do something right :S. I'm attempting to loop a background audio track while a game created in the console window is played. This is part of a group project. The game runs fine but I simply can't get the audio track to play using the PlaySound() function. This is a test program I made to try to figure out the problem.

#include <iostream>
#include <windows.h>
#include <mmsystem.h>

using namespace std;

int main()
{

    PlaySound(TEXT("D:\CodeBlocks:\Programming Work:\SoundTest:\castor.wav"), NULL, SND_FILENAME|SND_ASYNC|SND_LOOP);
    if(PlaySound(TEXT("D:\CodeBlocks:\Programming Work:\SoundTest:\castor.wav"), NULL, SND_FILENAME|SND_ASYNC|SND_LOOP))
    {
        cout << "It's Working." << endl;
    }
    else
    {
        cout << "It's not working." << endl;
    }
    cout << "Hello world!" << endl;

    return 0;
}

My test case returns true (or "It's working."), and when I tried it in the school computer lab, it would loop the default windows error tone, which plays when the function can't find the file you specified, even though I've given it the whole file path. I can't figure out why it can't find the file, I've quadruple checked that it is in fact located where I wrote the file path, and it still seems unable to find it. I've tried using both .mp3 and .wav formats for the audio file. Anyone know what's going on? (note: The linker needs to be given the winmm library for this)

Aucun commentaire:

Enregistrer un commentaire