Error playing wav file with SFML

When I try to play this wav file (or any audio file) with SFML, the exe outputs some crazy characters, kind of like instead of playing the audio, it is outputting the file's code.
http://yfrog.com/n6sfmlhelpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <SFML/Audio.hpp>
#include <iomanip>
#include <iostream>
using namespace std;
using namespace sf;

void PlaySound()
{
    // Load a sound buffer from a wav file
    SoundBuffer Buffer;
    if (!Buffer.LoadFromFile("footsteps.wav"))
        cout << "ERROR!" << endl;
    // Create a sound instance and play it
    Sound Sound(Buffer);
    Sound.Play();

    // Loop while the sound is playing
    while (Sound.GetStatus() == sf::Sound::Playing)
    {
        // Leave some CPU time for other processes
        Sleep(0.1f);

        // Display the playing position
        cout << "\rPlaying... " << std::fixed << std::setprecision(2) << Sound.GetPlayingOffset() << " sec   ";
    }
}
int main()
{
    // Play a sound
	cout << "TEST!" << endl;
	cin.get();
    PlaySound();
	cin.get();

    // Wait until the user presses 'enter' key
    cout << "Press enter to exit..." << std::endl;
    cin.ignore(10000, '\n');
	cout << "done" << endl;
	cin.get();

    return EXIT_SUCCESS;
}
Last edited on
Why are you cout'ing std::fixed and std::setprecision(2)?
I copied it from the tutorial and didn't switch it yet haha.
I've tried messing with other methods and files with sfml but it still has the same result =/.
Ok I figured it out, I needed to included the "-d" libs and dll's. I guess I needed to include them since it was for debug mode, but then when do I use the standard libs/dll's?
If you are using Visual Studio, change your build configuration to Release and then include the standard libs. As long as you have your DLL's in the same folder as your exe, your program will run.
Thanks, I had figured that out last night. That cleared up a whole bunch, but still I don't know much about Visual Studio.
Also, Make sure you define SFML_DYNAMIC at the beginning of your program(first line). You will encounter unknown errors if you don't
Thanks, I also learned that the hard way. VS is so picky haha.
http://sfml-dev.org/tutorials/1.6/start-vc.php:
Important: for the Debug configuration, you have to link with the debug versions of the libraries, which have the "-d" suffix (sfml-system-d.lib in this case). If you don't, you may get undefined behavior and crashes.


Just FYI
Topic archived. No new replies allowed.