Newbie question: One button to play AND pause audio, possible?

(Christina) #1

If I have a button, and click on it once, I would like it to play audio. And when audio is playing and I click again, I want it to pause/stop.

How can I achieve this the easiest way possible? I don’t need to change the look of button when clicked.

I hope someone can help me with this,
thank you SO much in advance,



Hi Christina!

Demo project: (339.7 KB)

In this Demo project “myAudio” is set as a global (in this case: “On Scene Load”)…

window.myAudio = hypeDocument.getElementById("myAudio1");

Note that the “id” is the id of the audio track as shown in the innerHTML of the button) NOT the button’s id set in the “Identity” panel.

The "playPause()" function in the Demo - which "toggles" between playing the sound and pausing it - is triggered by a button's "On Mouse Click" event. This function utilizes the [ternary operator](

(myAudio.paused) ? : myAudio.pause();

How to make a toggle button to toggle Audio Mute?