Forum Discussion

SuzanneNeafus's avatar
SuzanneNeafus
Community Member
9 months ago
Solved

Audio on States - is there a way to stop it

Greetings.   I have a slide with 5 boxes on it.  When you click a box, the information shows, and an audio file reads the text.  Right now, if they click on each one quickly, each audio file conti...
  • Nathan_Hilliard's avatar
    9 months ago

    Try creating a T/F variable called togAudioPauseAll.

    Then create an Execute JavaScript trigger and inserting the following code:

    const audioList = document.querySelectorAll("audio");

    for (let i = 0; i < audioList.length; i++) { audioList[i].pause(); }

    Set this trigger to fire when togAudioPauseAll changes.

    Whenever the user clicks a new box/button/whatever, use an Adjust Variable trigger to toggle togAudioPauseAll.

    This should stop all playing audio on the slide. Doing this before playing another audio clip lets you kill whatever audio is playing before the new one starts. It avoids having to create a bunch of individual triggers.