Sound stays active on resume #167

Open
WingEraser opened this Issue Jun 1, 2011 · 6 comments

Comments

Projects
None yet
4 participants

Howto produce:

  1. When a sound is playing, do a focus lost.
  2. Resume and the sound should be playing until it stops.
  3. The sound should stays active all the time even it is finished.

I need active, because I've to check when a sound is finished.

Owner

AdamAtomic commented Jun 1, 2011

are you using the latest version of master branch? i made some corrections to sound playback a little while ago, i'm just curious if this was before or after that, thanks!

I've use the latest version 2.55.
After you have made the quick fix from my previous issue, I redownloaded it from the master branch.

The problem is still there.

  1. Create a simple long sound, play it.
  2. In the update just do trace(sound.active) --> it should be true and false when it stops.
    The bug:
    1. When it is still playing, make it pause by leaving the window. Then resume, and it'll be always true even if the sound got finished.

WingEraser closed this Jun 2, 2011

whopes closed by wrong button

WingEraser reopened this Jun 2, 2011

noidexe commented Jun 2, 2011

I had the same issue and managed to fix it by adding one sentence to play() inside FlxSound.as:

Original

        /**
         * Call this function to play the sound - also works on paused sounds.
         * 
         * @param   ForceRestart    Whether to start the sound over or not.  Default value is false, meaning if the sound is already playing or was paused when you call <code>play()</code>, it will continue playing from its current position, NOT start again from the beginning.
         */
        public function play(ForceRestart:Boolean=false):void
        {
            if(_position < 0)
                return;
            if(ForceRestart)
            {
                var oldAutoDestroy:Boolean = autoDestroy;
                autoDestroy = false;
                stop();
                autoDestroy = oldAutoDestroy;
            }
            if(_looped)
            {
                if(_position == 0)
                {
                    if(_channel == null)
                        _channel = _sound.play(0,9999,_transform);
                    if(_channel == null)
                        exists = false;
                }
                else
                {
                    _channel = _sound.play(_position,0,_transform);
                    if(_channel == null)
                        exists = false;
                    else
                        _channel.addEventListener(Event.SOUND_COMPLETE, looped);
                }
            }
            else
            {
                if(_position == 0)
                {
                    if(_channel == null)
                    {
                        _channel = _sound.play(0,0,_transform);
                        if(_channel == null)
                            exists = false;
                        else
                            _channel.addEventListener(Event.SOUND_COMPLETE, stopped);
                    }
                }
                else
                {
                    _channel = _sound.play(_position,0,_transform);
                    if(_channel == null)
                        exists = false;

Added

                    else
                        _channel.addEventListener(Event.SOUND_COMPLETE, stopped);

Original

                }
            }
            active = (_channel != null);
            _position = 0;
        }

It didn't work for me. It keeps saying true. Shouldn't resume() be modified?

Example:
http://wingeraser.com/flixel/SoundTest.swf

Source (very simple code):
http://wingeraser.com/flixel/SoundTest.rar

axcho commented Feb 13, 2012

I've been having trouble with a similar issue, perhaps the same one.

I fixed it (hopefully without introducing other problems!) by adding a check in FlxG.resumeSounds() for active:

From this...
if((sound != null) && sound.exists)

To this...
if((sound != null) && sound.exists && sound.active)

And similarly for music.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment