Simultaneous movie with tones inserted throughout

OS: MacOS 11…6
PsychoPy version : 2021.2.3
Standard Standalone?: yes
What are you trying to achieve?:
For this experiment, I want participants to watch a continuous movie clip. In addition, I want to insert tones during the movie for an auditory oddball. The timing of the auditory oddball stimuli needs to be the same across all participants.

What specifically went wrong when you tried that?:
I tried to implement this in the coder and in the builder.

Here is a minimal working example of what I tried to do in the coder:

# Loading the oddball timing
tones = pd.read_csv('./OddballTiming.csv')
tones['stimulus'] = tones['tone']

# Create a sound stimulus for each trial
for tone in tones['tone'].unique():
    stimulus = sound.Sound(tone, sampleRate=44100, secs=0.5, stereo=True)
    tones['stimulus'].replace({tone: stimulus}, inplace=True)

# Loading the video
win = visual.Window((800, 600))
mov = visual.MovieStim3(win, '', size=(768, 576),
    flipVert=False, flipHoriz=False, loop=False)

# Preload the sounds with now+stimulus_onset
startTime = ptb.GetSecs()
for index, row in tones.iterrows():
    row['stimulus'].play(when=startTime + row['onset'])
    row['stimulus'].stop(when=startTime + row['onset'] + row['duration'])

# Display the movie
while mov.status != constants.FINISHED:

This shows the movie, but the sounds are not presented


The “movie_start” component loads the movie with a duration of 0.0s. The “movie_draw” component is a code block that calls movie.draw() at each frame. The “tone” component plays the sound with free parameters for the stimulus and the onset that are read from an csv file in the trial loop.

This attempt plays the sounds and the movie. However, the movie is not displayed smoothly. It seems to start and stop with every loop.

Any help on getting this to work in the builder or the code editor would be massively appreciated!