I’m new to coding, and am trying to set up an experiment where I will show both show images and movies (gifs) at the same time. To begin with, I’m trying to keep it very simple, and just want to make sure that the stimuli are shown on the screen in the positions where I want them. I have no problems showing the images, and it looks like the movie is loaded as well, but it doesn’t play. I have looked at how it has been set up in the MovieStim coder demo, but it still doesn’t work in my script. However, when I load the movie/gif into the demo, it does work. Does anybody know what I am doing wrong?
Here is my code:
from psychopy import core, visual, event, data, gui,
#Create window
win = visual.Window(size=(1920, 1080), screen=1, pos=(0,0), monitor=‘testMonitor’, fullscr=False, allowGUI=True, color=(0,0,0), units=‘pix’)
#Responses
resp_key =
‘’‘’
Load images and videos
‘’’
image0 = “Stimuli/000.png”
image1 = “Stimuli/000a.png”
image2 = “Stimuli/000b.png”
image3 = “Stimuli/000c.png”
videoimage0 = “Stimuli/053.gif”
videoimage1 = “Stimuli/055a.png”
videoimage2 = “Stimuli/055b.png”
videoimage3 = “Stimuli/055c.png”
‘’’
Define the positions of each stimulus
Position 0 = Target
Position 1 = Left stimulus
Position 2 = Middle stimulus
Position 3 = Right stimulus
‘’’
positions = {0: (0, 150),
1: (-300, -150),
2: (-0, -150),
3: (300, -150)}
stim_size = (180, 180) #Stimulus size in pixels
#Create stimuli
#Condition 1 stimuli
imagetarget = visual.ImageStim(win, image0, units=“pix”, pos=positions[0], size=stim_size)
imageposition1 = visual.ImageStim(win, image1, units=“pix”, pos=positions[1], size=stim_size)
imageposition2 = visual.ImageStim(win, image2, units=“pix”, pos=positions[2], size=stim_size)
imageposition3 = visual.ImageStim(win, image3, units=“pix”, pos=positions[3], size=stim_size)
#Condition 2 stimuli
videoimagetarget = visual.MovieStim(win, “Stimuli/055.gif”, units=“pix”, pos=positions[0], size=stim_size, loop=True, autoStart=True)
videoimageposition1 = visual.ImageStim(win, videoimage1, units=“pix”, pos=positions[1], size=stim_size)
videoimageposition2 = visual.ImageStim(win, videoimage2, units=“pix”, pos=positions[2], size=stim_size)
videoimageposition3 = visual.ImageStim(win, videoimage3, units=“pix”, pos=positions[3], size=stim_size)
#Condition 1
#Draw the stimuli
while True:
imagetarget.draw()
imageposition1.draw()
imageposition2.draw()
imageposition3.draw()
#Show stimuli and wait for response
win.flip()
key = event.waitKeys(maxWait=600, keyList=['esc', '1', '2', '3',], clearEvents=True)
if 'esc' in key:
break
elif '1' in key:
resp_key.append(1)
print("1 was pressed")
break
elif '2' in key:
resp_key.append(2)
print("2 was pressed")
break
elif '3' in key:
resp_key.append(3)
print("3 was pressed")
break
#Condition 2
#Draw the stimuli
while not videoimagetarget.isFinished:
videoimagetarget.draw()
videoimageposition1.draw()
videoimageposition2.draw()
videoimageposition3.draw()
#Show stimuli and wait for response
win.flip()
key = event.waitKeys(maxWait=600, keyList=['esc', '1', '2', '3',], clearEvents=True)
if 'esc' in key:
break
elif '1' in key:
resp_key.append(1)
print("1 was pressed")
break
elif '2' in key:
resp_key.append(2)
print("2 was pressed")
break
elif '3' in key:
resp_key.append(3)
print("3 was pressed")
break
videoimagetarget.unload()
print(resp_key)
core.quit