| Reference | Downloads | Github

Playing a sound only in a routine inside a loop

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

OS (e.g. Win10):
PsychoPy version (e.g. 1.84.x):
Standard Standalone? (y/n) If not then what?:
What are you trying to achieve?:
I want to play a sound inside a loop. The loop is composed of 3 routines. I want to play the sound only for the first two routines inside my loop

What did you try to make it work?:
By using custom code I added at the “Beginning experiment”:
background_sound = sound.Sound(‘01-White-Noise-10min.wav’)

“Beginning Routine”
if loop.thisN == 0:
“End Routine”
if trial_duration and warning_cueClock.getTime():

where: trial_duration and warning_cueClock.getTime() represent the time window for the first two routines in my loop.
That did not work as the sound actually stops at the end of my first routine within the loop and then it does not play anymore.
I also tried
if warning_cueClock == STARTED:

I guess that there should be a way to select just the first two routines inside the loop.
Please help me!
What specifically went wrong when you tried that?:
Include pasted full error message if possible. “That didn’t work” is not enough information.