MV How to check current playing Me?

I want to check the current playing Me. I dug around in the code a bit and found that there is a variable called AudioManager._currentMe; however when I try to log it to the console it just prints undefined while the Me is clearly playing the background. I want to do this because as soon as the Me is done playing I want to play a BGM. Anyone have any idea what I am doing wrong here?

JavaScript:
(function() {
    var checkForMeEndID;
    
    BattleManager.checkForMeEnd = function() {
        
        console.log($gameSystem.victoryMe());
        //console.log(Game_System.victoryMe());
    };
    
    BattleManager.playVictoryMe = function() {
        
        AudioManager.playMe($gameSystem.victoryMe());
        console.log(AudioManager._currentMe); //this is undefined. Why?
        checkForMeEndID = setInterval(this.checkForMeEnd, 1);
    };
    
    
    
})();
there is no such variable in AudioManager, that's why you get undefined
There is an AudioManager._currentBgm and AudioManager._currentBgs because those audios loop. There is a reference to this._currentMe, but it is not defined anywhere, so it seems like a bug.

Even if there were, just because the ME finishes playing, doesn't mean that variable would be cleared. It could simply contain a reference to the last ME that was played.
I searched through the MV code. There is indeed a reference to this._currentMe defined in the setter for AudioManager.meVolume. It's found in line 1160 of rpg_manager.js:

JavaScript:
Object.defineProperty(AudioManager, 'meVolume', {
    get: function() {
        return this._meVolume;
    },
    set: function(value) {
        this._meVolume = value;
        this.updateMeParameters(this._currentMe);
    },
    configurable: true
});

However, that is the only reference to that variable in the entire MV codebase. This means that while the variable is being used, nothing is ever stored in it, and therefore its value is always undefined.

Either someone forgot to implement this feature, or they forgot to remove it when it was decided that the feature wasn't going to be useful.

Adding this feature should be trivial, though. Simply extend AudioManager.updateMeParameters(me) to set this._currentMe = me; and extend AudioManager.stopMe() to set this._currentMe = null;.
Adding this feature should be trivial, though. Simply extend AudioManager.updateMeParameters(me) to set this._currentMe = me; and extend AudioManager.stopMe() to set this._currentMe = null;.
This works pretty well but I still have one issue. The two tracks I am playing (the Me and the BGM after the Me) are part of the same music composition. Its just it has an intro (the Me) and then the loop (the BGM) when I use the below code it works except there is a noticeable pause between the end of the Me and the start of the BGM. I want it to be instantaneous. I am already using an interval of 0. Any way I can make it instantaneous?

Code:
(function() {
    var checkForMeEndID;
    
    AudioManager.updateMeParameters = function(me) {
        this.updateBufferParameters(this._meBuffer, this._meVolume, me);
        this._currentMe = me;
    };
    
    AudioManager.stopMe = function() {
        this._currentMe = null;
        if (this._meBuffer) {
            this._meBuffer.stop();
            this._meBuffer = null;
            if (this._bgmBuffer && this._currentBgm && !this._bgmBuffer.isPlaying()) {
                this._bgmBuffer.play(true, this._currentBgm.pos);
                this._bgmBuffer.fadeIn(this._replayFadeTime);
            }
        }
    
    };
    
    BattleManager.checkForMeEnd = function() {
        
        console.log(AudioManager._currentBgm);
        //console.log(Game_System.victoryMe());
        if(AudioManager._currentMe === null) {
            const bgm = {
                name: 'Victory_Fanfare_Loop',
                pan: 0,
                pitch: 100,
                volume: 90,
                pos: 0
            };
            AudioManager.playBgm(bgm, bgm.pos);
        }
    };
    
    BattleManager.playVictoryMe = function() {
        console.log(AudioManager._currentBgm);
        AudioManager.playMe($gameSystem.victoryMe());
        checkForMeEndID = setInterval(this.checkForMeEnd, 0);
    };
    
    
    
})();
I don't think you need an interval for this. Worst case, the current ME hasn't finished playing yet, and your Victory Fanfare Loop won't play; best case, the current ME has already finished playing for a while, and you can hear the delay.

If I understand the code correctly, AudioManager.stopMe() will automatically resume playing the current BGM. So perhaps the simplest solution is to play the fanfare loop before playing the ME. That way, once the ME ends, the fanfare loop will automatically play.

So I'm guessing this should be enough:
JavaScript:
(function() {
    const bgm = {
        name: 'Victory_Fanfare_Loop',
        pan: 0,
        pitch: 100,
        volume: 90,
        pos: 0
    };

    const BattleManager_playVictoryMe = BattleManager.playVictoryMe;
    BattleManager.playVictoryMe = function() {
        AudioManager.playBgm(bgm);

        BattleManager_playVictoryMe.call(this);
    }
})();

You might be worried that the player can hear the fanfare loop before they hear the ME, but the code should be fast enough that the BGM won't have time playing before the ME plays.
If I understand the code correctly, AudioManager.stopMe() will automatically resume playing the current BGM. So perhaps the simplest solution is to play the fanfare loop before playing the ME. That way, once the ME ends, the fanfare loop will automatically play.
This while a good idea, did not seem to work. I did however after playing around with it for a few hours, get this to kinda work. The only problem is that the bgm fades in now but I want it to start at full volume. I am not sure how to make it do that. I tried changing the this.replayFadeTime to 0 to make it fade in instantaneously but this did not work. Also tried 1. Still nothing. Also tried changing this._bgmBuffer.fadeIn to this._bgmBuffer.play but the music still fades in.

Code:
(function() {
    var checkForMeEndID;
    var playingVictory = false;
   
    AudioManager.replayBgm = function(bgm) {
    console.log("Called");
    if (this.isCurrentBgm(bgm)) {
        this.updateBgmParameters(bgm);
    } else {
        this.playBgm(bgm, bgm.pos);
        if (this._bgmBuffer) {
            this._bgmBuffer.fadeIn(this._replayFadeTime);
        }
    }
};
   
    AudioManager.updateMeParameters = function(me) {
        this.updateBufferParameters(this._meBuffer, this._meVolume, me);
        this._currentMe = me;
        BattleManager.checkForMeEnd();
    };
   
    AudioManager.stopMe = function() {
        this._currentMe = null;
       
        if (this._meBuffer) {
            this._meBuffer.stop();
            this._meBuffer = null;
            BattleManager.checkForMeEnd();
            if (this._bgmBuffer && this._currentBgm && !this._bgmBuffer.isPlaying()) {
                this._bgmBuffer.play(true, this._currentBgm.pos);
               
                if(playingVictory) {
                    this._bgmBuffer.fadeIn(1);
                    playingVictory = false;
                }  else {
                    this._bgmBuffer.fadeIn(this._replayFadeTime);
                }
               
            }
        }
   
    };
   
    BattleManager.checkForMeEnd = function() {
       
        console.log(AudioManager._currentBgm);
        //console.log(Game_System.victoryMe());
        if(playingVictory && AudioManager._currentMe === null) {
            const bgm = {
                name: 'Victory_Fanfare_Loop',
                pan: 0,
                pitch: 100,
                volume: 90,
                pos: 0
            };
            AudioManager.playBgm(bgm, bgm.pos);
           
        }
    };
   
    BattleManager.playVictoryMe = function() {
        playingVictory = true;
        console.log(AudioManager._currentBgm);
        AudioManager.playMe($gameSystem.victoryMe());
        checkForMeEndID = setInterval(this.checkForMeEnd, 0);
    };
   
   
   
})();
I tried changing the this.replayFadeTime to 0 to make it fade in instantaneously but this did not work.

That's because you're using this._replayFadeTime only when:
  1. You're NOT playing the victory fanfare.
  2. You're replaying a BGM that is not the current BGM.
Neither of which are relevant to what you're trying to achieve.

Have you tried changing:
JavaScript:
this._bgmBuffer.fadeIn(1);
to:
JavaScript:
this._bgmBuffer.fadeIn(0);
?
I tried that too but its still not working. Its okay though because I asked the author of the music for a combined version of the music and he actually helped me out. Hate to leave this unsolved but at least I kinda got a solution now.
I see. I'm glad you found a solution, though I'm also sorry I couldn't be of more help.

Original thread: https://forums.rpgmakerweb.com/threads/how-to-check-current-playing-me.143096/