SFML community forums
Help => Audio => Topic started by: GroundZero on September 01, 2011, 03:25:59 pm
-
Dear reader,
kan someone tell me how to play music and -or sounds correctly?
I tried the code from 2.0 documentation but no error, but neither sound or any thing.
Could someone make me a simple code so I can see the proper way?
I am useing SFML 2.0
Best regards
-
The documentation code is supposed to be the simple/proper one. Show us your code if it doesn't work.
Have you tried the "sound" SFML example?
-
sf::SoundBuffer buffer;
if (buffer.LoadFromFile("sound/laugh.wav")) {
sf::Sound sound;
sound.SetBuffer(buffer);
sound.Play();
}
All it does with this code is give me a error:
Starting C:\Users\Ground Zero\Desktop\C++\leren\GAME\game-build-desktop\debug\test.exe...
C:\Users\Ground Zero\Desktop\C++\leren\GAME\test-build-desktop\debug\test.exe exited with code -1073741515
-
sf::SoundBuffer buffer;
if (buffer.LoadFromFile("sound/laugh.wav")) {
sf::Sound sound;
sound.SetBuffer(buffer);
sound.Play();
}
All it does with this code is give me a error:
Starting C:\Users\Ground Zero\Desktop\C++\leren\GAME\game-build-desktop\debug\test.exe...
C:\Users\Ground Zero\Desktop\C++\leren\GAME\test-build-desktop\debug\test.exe exited with code -1073741515
Complete and minimal code please.
-
...the problem is that your main thread exits before the audio playing thread could play any samples, and kills any spawned threads. if you insert this line right after sound.Play() the code will work fine.:
sf::Sleep(sound.GetDuration());