Author Topic: Bug in stopping music?  (Read 1895 times)

test84

  • Key Contributor
  • *****
  • Posts: 1328
  • Karma: +0/-0
  • ت
    • View Profile
    • My personal site.
Bug in stopping music?
« on: Sat, Apr 7, 2012 »
Hi,

When I want to stop a music that I played back with FlxG.playMusic, I use either FlxG.music.stop() or FlxG.pauseSounds() and it worked until now that I discovered if after calling either of these functions, your game loses focus and gains it back, the music track starts again automatically!

So is there a better way to stop a music track that you played back with FlxG.playMusic ?

I know that we get a FlxSound handle when we use FlxG.play that we can use to mute it but we don't get any pointers from FlxG.playMusic.

Thanks.
« Last Edit: Sat, Apr 7, 2012 by test84 »
blog, twitter, Check out my award winning game, Rot Gut:

zenmasters

  • Member
  • **
  • Posts: 15
  • Karma: +0/-0
    • View Profile
Re: Bug in stopping music?
« Reply #1 on: Sun, Apr 8, 2012 »
Whoa! So I've got a bug in my game that I didn't even know about! :o

OK... the solutions seems to be pretty simple, at least for me, as I use the FlxG.pause boolean for handling my own pause behaviour.

FlxG.as, line 648
Code: [Select]
static public function resumeSounds():void
{
if((music != null) && music.exists)
music.play();

Let's change the condition to:
(music != null) && music.exists && !paused

It works fine.

As for the 'pointer' to the music - it's just FlxG.music ;)
« Last Edit: Sun, Apr 8, 2012 by zenmasters »

auriplane

  • Snails!!
  • Contributor
  • ****
  • Posts: 497
  • Karma: +1/-0
  • Snails!!
    • View Profile
Re: Bug in stopping music?
« Reply #2 on: Sun, Apr 8, 2012 »
You can loop a very short silent MP3 instead.  Actually, new sound effects when nothing's playing can be pretty latent in Flash, so playing silence isn't such a bad idea.

test84

  • Key Contributor
  • *****
  • Posts: 1328
  • Karma: +0/-0
  • ت
    • View Profile
    • My personal site.
Re: Bug in stopping music?
« Reply #3 on: Sun, Apr 8, 2012 »
Whoa! So I've got a bug in my game that I didn't even know about! :o

OK... the solutions seems to be pretty simple, at least for me, as I use the FlxG.pause boolean for handling my own pause behaviour.

FlxG.as, line 648
Code: [Select]
static public function resumeSounds():void
{
if((music != null) && music.exists)
music.play();

Let's change the condition to:
(music != null) && music.exists && !paused

It works fine.

As for the 'pointer' to the music - it's just FlxG.music ;)

Now if you pause the game, then your game looses focus and gets it back and you unpause, your music will not resume.
blog, twitter, Check out my award winning game, Rot Gut:

zenmasters

  • Member
  • **
  • Posts: 15
  • Karma: +0/-0
    • View Profile
Re: Bug in stopping music?
« Reply #4 on: Wed, Apr 11, 2012 »
Here's my function that is invoked by the Resume button:

Code: [Select]
public function pauseResume():void
{
pauseMenu.hidePause();
FlxG.paused = false;
FlxG.music.play();
FlxG.mouse.reset();
}