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
#include <SFML/Audio.hpp>
#include <iomanip>
#include <iostream>
usingnamespace std;
usingnamespace 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;
}
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.
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.