Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: (Noob question) How do you play music once?  (Read 3622 times)

0 Members and 1 Guest are viewing this topic.

MaeZer

  • Newbie
  • *
  • Posts: 9
    • View Profile
(Noob question) How do you play music once?
« 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?

shadowmouse

  • Sr. Member
  • ****
  • Posts: 302
    • View Profile
Re: (Noob question) How do you play music once?
« Reply #1 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.

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: (Noob question) How do you play music once?
« Reply #2 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;
}

MaeZer

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: (Noob question) How do you play music once?
« Reply #3 on: May 27, 2015, 05:05:57 pm »
Thanks for both the answers, I got it to work now.

 

anything