gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 23:07:41 26 4
gpt4 key购买 nike

我在 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()

我尝试添加类似于最后一个 block 的代码,该代码在 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

最佳答案

您真正想要中断的循环是:

while mov.status != visual.FINISHED:

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

例如:

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

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

关于python - 使用 MovieStim2 在 PsychoPy 中基于按键跳过视频(循环),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32082951/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com