I am trying to play an .ogg file in SFML, I have all the DLLs and the libraries etc, but for some reason nothing plays when I start the code. I have read the tutorials and have looked around a bit to see if I could fix it myself, but had no avail. I think it might have something to do with the buffer in the wrong place, but not sure. Furthermore the window freezes when opened, don't know what is wrong. Any ideas?
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/Audio.hpp>
int main()
{
sf::Window window(sf::VideoMode(800, 600), "My window");
sf::SoundBuffer buffer;
buffer.loadFromFile("mine.ogg");
sf::Sound sound;
sound.setBuffer(buffer);
while (window.isOpen())
{
sound.play();
}
}
I moved the sound.play(); outside of the loop, but still not hearing anything :-\ I also tried with sf::music, and with different files.
Show your updated code. Alternatively try the included examples that come with SFML.
Okay thanks, here is my code
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
int main()
{
// create the window
sf::RenderWindow window(sf::VideoMode(800, 600), "My window");
sf::SoundBuffer buffer;
buffer.loadFromFile("mine.ogg");
sf::Sound sound;
sound.setBuffer(buffer);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
// check the type of the event...
switch (event.type)
{
// window closed
case sf::Event::Closed:
window.close();
break;
}
}
}
sound.play();
}