diff --git a/source/funkin/audio/FunkinSound.hx b/source/funkin/audio/FunkinSound.hx index 06ba48e81..cf28ed08e 100644 --- a/source/funkin/audio/FunkinSound.hx +++ b/source/funkin/audio/FunkinSound.hx @@ -90,6 +90,11 @@ class FunkinSound extends FlxSound implements ICloneable */ var _label:String = "unknown"; + /** + * Whether we received a focus lost event. + */ + var _lostFocus:Bool = false; + public function new() { super(); @@ -177,7 +182,10 @@ class FunkinSound extends FlxSound implements ICloneable */ override function onFocus():Void { - if (!_alreadyPaused) + // Flixel can sometimes toss spurious `onFocus` events, e.g. if the Flixel debugger is toggled + // on and off. We only want to resume the sound if we actually lost focus, and if we weren't + // already paused before we lost focus. + if (_lostFocus && !_alreadyPaused) { resume(); } @@ -185,6 +193,7 @@ class FunkinSound extends FlxSound implements ICloneable { trace('Not resuming audio on focus!'); } + _lostFocus = false; } /** @@ -193,6 +202,7 @@ class FunkinSound extends FlxSound implements ICloneable override function onFocusLost():Void { trace('Focus lost, pausing audio!'); + _lostFocus = true; _alreadyPaused = _paused; pause(); }