SFML community forums

Help => Audio => Topic started by: Patrik on January 22, 2012, 04:34:11 pm

Title: No Sound on a basic window application
Post by: Patrik on January 22, 2012, 04:34:11 pm
Hey guys,

I've made a simple window application with SFML and although I've
loaded the needed sound there comes no music. But otherwise
everything is running well.

Here's the source code:

Code: [Select]

#include <SFML/System.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>

using namespace sf;

int main(){
    RenderWindow Window(VideoMode(600, 400, 32), "The Deployment - Here they come!");
    while(Window.IsOpened()){
        Event Close;
        while(Window.GetEvent(Close)){
            if(Close.Type == Event::Closed){
                Window.Close();
            }
        }
        Music BackgroundMusic;
        if(!BackgroundMusic.OpenFromFile("/usr/local/games/The Deployment/sounds/BGSound.ogg")){
            return 0;
        }
        BackgroundMusic.SetLoop(true);
        BackgroundMusic.SetVolume(75.f);
        BackgroundMusic.Play();
        Window.Clear(Color(0, 191, 255));
        Window.Display();
    }
    return 0;
}


I using Code::Blocks on Ubuntu 11.10 and the needed libraries are all linked.

Thanks for any help,
Patrik
Title: No Sound on a basic window application
Post by: Laurent on January 22, 2012, 04:55:30 pm
Open/play the music before the main loop.
Title: No Sound on a basic window application
Post by: Patrik on January 22, 2012, 05:03:51 pm
Thanks Laurent, now does it works  :D