Forum Discussion

SuzanneNeafus's avatar
SuzanneNeafus
Community Member
3 months ago

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 continues to play on top of the other. 

Is there a way to stop the audio if someone chooses another box?  At first, I thought I could resolve this by adding triggers, but those buttons are unavailable when editing a state.

Any help would be appreciated.  Thank you

Suzanne

  • A simple way to control multiple audio clips is to put each one on its own layer. When a trigger shows one layer, the default setting in Slide Layer Properties is to hide other layers. That "turns off" the audio on the hidden layer.

  • But, is there a way to do it with the states?   If I have to rewrite the whole slide I will but would much rather just add something to what's already there if it is possible. 

    Thank you -

    Suzanne

  • 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.

     

    • CarrieMaddern-a's avatar
      CarrieMaddern-a
      Community Member

      Thank you for sharing this Nathanial! Solved the problem for me.

  • I ran into this recently when creating a training, and the way I got the audio to stop was to do a trigger to "Stop Media" when "User Clicks" and that seemed to resolve it pretty simply.