caethyril

^_^
Global Mod
Joined
Feb 21, 2018
Messages
3,045
Reaction score
2,358
First Language
EN
Primarily Uses
RMMZ
Seen in RMMZ core scripts up to the current version (v1.4.0).

Edit 2021-12-09: as of v1.4.0, Effekseer pauses when the game is out of focus, but audio does not. The thread title and content have been updated to reflect this.

(This thread was previously titled "Audio + Effekseer do not pause when game loses focus".)

Description​

The current scene updates only if the game is in focus. Audio does not pause/resume in the same way. This discrepancy can cause in-game desynchronisation, e.g.
  1. A cutscene timed to its BGM.
    • v1.4.0 - no change.
  2. Audio cues for Effekseer animations.
    • v1.4.0 - partial fix: new sound cues will no longer trigger when paused.
      Audio already playing will continue to play as it would if the game were not paused.

Steps to reproduce​

  1. Start the game.
  2. Play any audible track in-game (BGS, BGM, ME, SE), e.g. via:
    • The Autoplay BGM and/or Autoplay BGS map settings;
    • A Play BGM, Play BGS, Play ME, or Play SE event command;
    • A corresponding script command via event or console; or
    • An animation with at least one audio cue.
  3. Make the game lose focus while the audio is playing, e.g. by clicking on the editor or console.
  4. The audio will continue to play while the scene is "paused".

Technical explanation​

The game's underlying audio updates independently of the SceneManager. This loop continues regardless of whether or not SceneManager.isGameActive() is true. More information on the Web Audio context object can be found here:

Potential fix​

Apply the relevant pause/resume methods when the game focus changes, e.g.
JavaScript:
/*:
 * @target MZ
 * @help Free to use and/or modify for any project.
 */

(function(alias) {
'use strict';

    let isActive = true;

    const getAudioContext = function() {
        return WebAudio._context;
    };

    const pauseAudio = function(context, active) {
        if (active) context.resume();
        else        context.suspend();
    };

    const updateActive = function() {
        pauseAudio(getAudioContext(), isActive);
    };

    SceneManager.updateScene = function() {
        const active = this.isGameActive();
        if (isActive !== active) {
            isActive = active;
            updateActive();
        }
        alias.apply(this, arguments);
    };

})(SceneManager.updateScene);
JavaScript:
/*:
 * @target MZ
 * @help Free to use and/or modify for any project.
 */

(function(alias) {
'use strict';

    let isActive = true;

    const getAudioContext = function() {
        return WebAudio._context;
    };

    const getEffekseerHandles = function() {
        return (SceneManager._scene._spriteset?._animationSprites || [])
                .map(s => s._handle)
                .filter(h => h);
    };

    const pauseAudio = function(context, active) {
        if (active) context.resume();
        else        context.suspend();
    };

    const pauseEffekseer = function(handles, active) {
        handles.forEach(h => h.setPaused(!active));
    };

    const updateActive = function() {
        pauseAudio(getAudioContext(), isActive);
        pauseEffekseer(getEffekseerHandles(), isActive);
    };

    SceneManager.updateScene = function() {
        const active = this.isGameActive();
        if (isActive !== active) {
            isActive = active;
            updateActive();
        }
        alias.apply(this, arguments);
    };

})(SceneManager.updateScene);
Edit 2021-12-18: this approach to pause the audio only seems to work correctly for BGM, BGS, and ME buffers; SE buffers (un)mute correctly, but it seems they update their seek/play position while muted. I'm not sure why, though. :kaoslp:
 
Last edited:

caethyril

^_^
Global Mod
Joined
Feb 21, 2018
Messages
3,045
Reaction score
2,358
First Language
EN
Primarily Uses
RMMZ
Updated for 1.4.0 (great update by the way!). Effekseer animations now pause when the game loses focus, but audio does not. I've edited the post/thread to reflect this and made a few other clarifications.

I'm guessing the Effekseer part of this report eclipsed the audio part. However, if non-pausing audio is actually not considered a bug then I'd appreciate feedback on that. No rush, though~

[Edit: I just realised that SE channels specifically seem to keep "playing" while suspended, so I'm guessing that's the reason nothing was done with the audio yet. :kaoswt:]

Cheers! :kaohi:
 
Last edited:

Latest Threads

Latest Posts

Latest Profile Posts

I have never felt so attacked by a tree before :LZSlol: it took 10++ hours to make but at least it looks pretty LOL

Untitled-1.png
now seems like the worst time for me to need a better computer with how much stuff is costing. that and I don't thing there's much else I can do to make MV run any better with what I have.
Sigh... to have some variety in this weather. More than just sun and rain and wind and thunder.
In the meantime, I've discovered that I'm slowly becoming fatigued from the many sleepless nights my neighbors cause. Or at least their dogs. Always barking at something.
I might need a day to just sleep and recharge.
After the initial success with one event, I set up four different events on the same map to detect who is in which slot in my current party, and fortunately it managed to work as intended, with the events changing image to match the party members even as I swapped their positions around in formation. This will be a great tool for immersive scene design.

Forum statistics

Threads
118,452
Messages
1,116,086
Members
155,428
Latest member
jlauza
Top