Check currently playing ME

I tried using "RPG::ME.name == " to check which ME is currently playing, but it doesn't seem to work. it works with BGM ("RPG::BGM.last.name == ") but the thing is I need it to be an ME
I have moved this thread from RGSS3 Scripts (RMVX Ace) to RPG Maker VXAce Support.
When the music is played the data values are deleted as the instance that called it is deleted.
At least that's how I understand it, since no matter what you do the value cannot be read once the music is played. Even while the music is played. The memory reference is gone.

Add this into your script editor and select the variable to use for saving the name then you can do a check against the variable or with the script call RPG::ME.lastname
Ruby:
#==============================================================================
# ■ RPG::ME
#==============================================================================
module R2_Save_ME_Name
  VAR = 3
end

class RPG::ME < RPG::AudioFile
  attr_reader :lastname
  #--------------------------------------------------------------------------
  # overwrite method: play
  #--------------------------------------------------------------------------
  def play
    if @name.empty?
      Audio.me_stop
    else
      $game_variables[R2_Save_ME_Name::VAR] = @name.to_s
      Audio.me_play('Audio/ME/' + @name, @volume, @pitch)
    end
  end

  #--------------------------------------------------------------------------
  # new method: filename
  #--------------------------------------------------------------------------
  def self.lastname
    return $game_variables[R2_Save_ME_Name::VAR]
  end
 
end # RPG::ME
Actually, it's extremely easy to implement without using a single game variable.

EDIT 1: I had to fix an issue at line 8 to make sure ME's would certainly stop at the script's request.

EDIT 2: Later on I revisited my scriptlet to fix the module / class scope issue that it triggered while creating a new ME object.

Ruby:
# * RPG::ME Extended * #
#  2024-05-04

module RPG
  class ME
    @@last = ME.new
    def play
      if @name.empty?
        Audio.me_stop
        @@last = ME.new
      else
        Audio.me_play('Audio/ME/' + @name, @volume, @pitch, pos)
        @@last = self.clone
      end
    end
    alias :replay :play

    def self.stop
      Audio.me_stop
      @@last = ME.new
    end

    def self.fade(time)
      Audio.me_fade(time)
      @@last = ME.new
    end

    def self.last
      @@last
    end
  end
end
I never remember about class variables, haven't used them yet.

Original thread: https://forums.rpgmakerweb.com/threads/check-currently-playing-me.167728/