SFML community forums

Help => Audio => Topic started by: MaeZer on May 27, 2015, 04:43:59 pm

Title: (Noob question) How do you play music once?
Post by: MaeZer on May 27, 2015, 04:43:59 pm
Hi, as the title says I'm new to this. But anyways I can't think how one would check if a sound file had finished playing or something like that, so I can play it just once? The problem I have is that when the left mouse button is pressed, it constantly plays the music file over and over again until it is not pressed. I can't figure out how to play it just once. What am I missing here?
Title: Re: (Noob question) How do you play music once?
Post by: shadowmouse on May 27, 2015, 04:51:04 pm
Have a look at the getStatus() and setLoop() functions. As you haven't posted code, I don't know exactly what the problem is, but it is either than you're restarting the music repeatedly because the mouse is still clicked, or it is set to loop.
Title: Re: (Noob question) How do you play music once?
Post by: Jesper Juhl on May 27, 2015, 04:51:16 pm
There are many ways to do that. Here's a simple one:

static bool played_once = false;
if (!played_once) {
    music.play();
    played_once = true;
}
Title: Re: (Noob question) How do you play music once?
Post by: MaeZer on May 27, 2015, 05:05:57 pm
Thanks for both the answers, I got it to work now.