MZ Easiest way to wait until a sound effect has finished playing

Hi, I've got this vast directory of sound effects and my particular application can access them programmatically. The problem is, sometimes I need to play one after the other. I need to know that the first one has finished before starting the next one. What is the easiest way to do this?

For whatever reason I chose to use MZ instead of MV and so maybe the MV plugins that seem to handle this may not work. In any case, I want the simplest solution I can get.
I just tried the following script call setup and it seemed to work for me in a couple of quick tests:
Spoiler: event example (stop listener)
◆Comment:Play sound effect. ◆Play SE:Battle6 (2, 50, 0) ◆Comment:Initialise switch. ◆Control Switches:#0001 SE stopped = OFF ◆Comment:Add a stop listener to the most recent SE buffer, : :to make it turn on a switch when the SE stops. ◆Script:const switchId = 1; : :const b = AudioManager._seBuffers; : :b[b.length - 1].addStopListener( : : () => $gameSwitches.setValue(switchId, true) : :); ◆Comment:Check each frame until the switch turns on. ◆Loop ◆If:SE stopped is ON ◆Break Loop ◆ :End ◆Wait:1 frame ◆ :Repeat Above ◆Text:None, None, Window, Bottom : :All done!
Easy-copy version of the Script command:
JavaScript:
const switchId = 1;
const b = AudioManager._seBuffers;
b[b.length - 1].addStopListener(
  () => $gameSwitches.setValue(switchId, true)
);
Replace the 1 on the first line with the ID of the switch you're using.
I think this should also play nicely with any plugin that allows pausing audio. 👋

Original thread: https://forums.rpgmakerweb.com/threads/easiest-way-to-wait-until-a-sound-effect-has-finished-playing.152870/