SFML community forums

Help => Audio => Topic started by: GroundZero on September 01, 2011, 03:25:59 pm

Title: Music how to?
Post 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
Title: Music how to?
Post by: Laurent on September 01, 2011, 03:30:18 pm
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?
Title: Music how to?
Post by: GroundZero on September 01, 2011, 04:07:23 pm
Code: [Select]
   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
Title: Music how to?
Post by: OniLinkPlus on September 02, 2011, 02:03:53 am
Quote from: "GroundZero"
Code: [Select]
   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.
Title: Music how to?
Post by: atmamta on November 22, 2011, 06:06:53 pm
...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());