Author Topic: Sound issue when pausing  (Read 1009 times)

Noid.EXE

  • Member
  • **
  • Posts: 11
  • Karma: +0/-0
    • View Profile
    • NoidEXE on deviantART
Sound issue when pausing
« on: Tue, May 24, 2011 »
I submitted this as a bug, but Adam says he couldn't reproduce it so maybe it's something wrong with my code.

This is the simplest code that should reproduce the issue(requires flixel 2.55).

Code: [Select]
package
{

import org.flixel.*;

public class PlayState extends FlxState
{
[Embed(source = 'data/cartridge.mp3')] private var sndCart:Class;
private var testSound:FlxSound;

override public function create():void
{

testSound = FlxG.loadSound(sndCart);

}

override public function update():void
{
FlxG.keys.SPACE ? testSound.play(true) : testSound.play() ; // using play(true) makes it work again until the next pause/unpause
super.update();
}

}
}
Sound: https://github.com/noidexe/Soundtest/blob/master/src/data/cartridge.mp3?raw=true

If you compile it you'll notice a sound that plays again and again.
If you click in some other window, the game, and the sound pauses, as it should. However, if click again on the game to unpause it you'll notice the sound finishes playing and stops, even with play() being called in every frame.
The only way to restart the sound is is calling play(true)(press SPACE) and it works until the next time you pause the game.

You can try it with this binary http://cloud.github.com/downloads/noidexe/Soundtest/Soundtest.swf or this project https://github.com/noidexe/Soundtest

photonstorm

  • Administrator
  • Key Contributor
  • *****
  • Posts: 1502
  • Karma: +1/-0
    • View Profile
    • Photon Storm
Re: Sound issue when pausing
« Reply #1 on: Tue, May 24, 2011 »
Right this is odd - in your SWF I can replicate the problem consistently.

In a SWF I compile here (2.55, exact same source code) it works fine with the beep.mp3 from flixel.

Swap the beep for your mp3 and it works fine about 50% of the time. The rest of the time it acts as you describe. But it's not consistent at all. I was literally clicking away, then back again, then away, then back, and having maybe a 50% success rate.

My guess is there is a flaw in the flixel logic somewhere to do with the position offset the sound is restarted at, but I've not found it yet (and am not likely to have time to, but I would narrow your search there)
http://www.photonstorm.com



"Tell me and I will forget, show me and I might remember, involve me and I will understand" - Confucius

Noid.EXE

  • Member
  • **
  • Posts: 11
  • Karma: +0/-0
    • View Profile
    • NoidEXE on deviantART
Re: Sound issue when pausing
« Reply #2 on: Tue, May 24, 2011 »
Thanks for the info.
One question, I'm still using the Flex 4 that comes with FlashDevelop, are you using the new Flex 4.5(Hero) released a few weeks ago? It's the only thing I haven't tried.
« Last Edit: Tue, May 24, 2011 by Noid.EXE »

photonstorm

  • Administrator
  • Key Contributor
  • *****
  • Posts: 1502
  • Karma: +1/-0
    • View Profile
    • Photon Storm
Re: Sound issue when pausing
« Reply #3 on: Wed, May 25, 2011 »
Flex 4. I had to change your code a bit though and move the creation of the testSound var into a create function. It didn't work in the constructor (not sure why, it was 3am and I didn't care to check further)
http://www.photonstorm.com



"Tell me and I will forget, show me and I might remember, involve me and I will understand" - Confucius

Noid.EXE

  • Member
  • **
  • Posts: 11
  • Karma: +0/-0
    • View Profile
    • NoidEXE on deviantART
Re: Sound issue when pausing
« Reply #4 on: Wed, May 25, 2011 »
I think I fixed it.

Code: [Select]
org/flixel/FlxSound.as |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/org/flixel/FlxSound.as b/org/flixel/FlxSound.as
index 2c9b367..62525a3 100644
--- a/org/flixel/FlxSound.as
+++ b/org/flixel/FlxSound.as
@@ -358,6 +358,11 @@ package org.flixel
  _channel = _sound.play(_position,0,_transform);
  if(_channel == null)
  exists = false;
+ else
+ {
+ _channel.addEventListener(Event.SOUND_COMPLETE, stopped);
+
+ }
  }
  }
  active = (_channel != null);