How to do a Play/Pause button?

If this template helps then use it. If not then just delete and start from scratch.

OS : macOS 12.6 (Monterey)
PsychoPy version : v2022.2.4
Standard Standalone? (y/n) : y
What are you trying to achieve?:
Hi everyone, begginer on PsychoPy and not very comfortable with the code, I use the Builder version for doing my experiments.
I would like to build an experiment with many sound button on the same screen followed by slider scale.

What did you try to make it work?:
For this I create a sound component which start at a mouse click on an image

My mouse has as parameter the image for clicking on it :

So create a play button is quite easy.

What specifically went wrong when you tried that?:
Unfortunately, I cannot create a pause or even a stop button because the sound cannot take a condition as a stop, only a duration. How can I create a pause button, or at least a stop ? It would be useful for putting many sounds on the screen where the subject can pause one of them for listening an other one.

Thank you very much in advance for yours answers :blush:

Hi @X-Draque, I think this needs to be all done in code. You can add a code component and the following code in

Every frame

if mouse.isPressedIn(image):
    if dtp.status == "NOT_STARTED" or dtp.status == "FINISHED":
    if dtp.status == "STARTED":

I have not tested this so let me know if it works or if it needs adjustments. It could be that you need to force your sound component to not be played in any way except for the code starting it, so maybe set condition to False.

Hi ajus, thank you for your help.
I tried with this version of a code and it’s not working :

The code is implemented in all windows from Begin Routine to End Experiment just in case.

Here is the configuration of the mouse2 (I create this because I don’t know if a mouse could have more than 1 clickable stimuli :

Hi! It took some debugging, but this is a minimal example that you can use as a blueprint. Make sure to use the ptb audio backend (settings → audio).

pause.psyexp (11.3 KB)