使用 MovieStim2 基于 PsychoPy 中的按键跳过视频(循环)

skip a video (in a loop) based on keypress in PsychoPy using MovieStim2

我在 PsychoPy 中使用 MovieStim2 播放了 3 个视频。不过,我怀疑这个问题源于没有真正理解循环。

我想在参与者按下一个键时跳到下一个视频。我了解当参与者按下 "q" 时我的代码如何退出,但我不确定如何使其在他们按下 "b" 时跳到下一个视频。这是我当前的代码:

vidNum = 1
for f in ['clip1.mpg', 'clip2.mpg', 'clip3.mpg']:
    clock.reset()
    #logfile.write("AfterForLoopTime,%s,Video %s\n" % (core.getTime(), vidNum))
# Create your movie stim.
    mov = visual.MovieStim2(win, videopath+f,
                       size=640,
                       # pos specifies the /center/ of the movie stim location
                       pos=[0, 0],
                       flipVert=False,
                       flipHoriz=False,
                       ) # loop=False - need to comment this to use a loop

# Start the movie stim by preparing it to play
    shouldflip = mov.play()
    logfile.write("AfterShouldflipLine58,%s, Video %s\n" % (clock.getTime(), vidNum))
    while mov.status != visual.FINISHED:
    # Only flip when a new frame should be displayed. Can significantly reduce
    # CPU usage. This only makes sense if the movie is the only /dynamic/ stim
    # displayed.
        if shouldflip:
        # Movie has already been drawn , so just draw text stim and flip
        #text.draw()
            win.flip()
        else:
        # Give the OS a break if a flip is not needed
            time.sleep(0.001)
    # Drawn movie stim again. Updating of movie stim frames as necessary
    # is handled internally.
        shouldflip = mov.draw()

    # Check for action keys.....
        for key in event.getKeys():
            if key in ['escape', 'q']:
                win.close()
                core.quit()

我尝试添加类似于在 q:

之后退出的最后一个块的代码
            elif key in ['b']:
                break

但我意识到我真的很想跳出这个循环:

for f in ['clip1.mpg', 'clip2.mpg', 'clip3.mpg']:

然而,这似乎也不起作用

for f in ['clip1.mpg', 'clip2.mpg', 'clip3.mpg']:
    for key in event.getKeys():
        if key in ['b']:
           break

您真正想要 break 的循环是:

while mov.status != visual.FINISHED:

我能想到的最简单的方法是在用户按下该键时将您的电影状态设置为 -1(或 visual.FINISHED)。

例如:

if key in ['b']:
    mov.status = -1

据我所知,这将使您脱离当前的视频。