Using movieStim3 to present peripheral short videos

Hello,

I am currently trying to modify a script previously used in the group. For this current study, the objective is to present black bars to the participants which will be tilted. The participant will then indicate with the arrows of the keyboard to which side the bar is tilted and will subsequently receive feedback (a 1 second video will appear peripherally on the screen).
So the steps in the code are:

  • Cross in the middle appears
  • Cross disappears
  • Bar appears for 200 ms
  • Bar disappears
    -Cross appears and stays waiting for participant’s response (press of either right or left arrow)
  • Cross continues on the screen
  • Short video appears on either side of the screen
  • restart the loop

My main problem is: everything is working but the video. The video does not show on the screen, however there are no error messages and the code for the video works fine when done completely separately.
The system I am using is linux and psychopy version is 2021.2.3.

trials.py (13.2 KB)

I’ve uploaded the script for better comprehension, but the main part of the code I need help with is the following:

import os
from psychopy import visual, core, monitors, event, constants, prefs#, gui
prefs.hardware['audioLib'] = ['PTB', 'sounddevice', 'pyo', 'pygame']
print(prefs)
from psychopy import sound
import pylink
import random
import local_settings
from get_sample import gaze_square, gaze_ellipse #gaze-contingency routine
import sys
import cv2
import time

        def comp_main(this_stimuli, win, fixkreuz, timer, tracker, p_port, background, this_central_stimuli, dataFileName):
        core.wait(0.5)
        
        central_bar = visual.ImageStim(win=win, size=[50, 200], name="cent_bar", pos=(0, 0),
                                          image=this_central_stimuli.file_path) #central bar
        fix_time = random.randrange(1500, 2500) / 1000.0 #randomise inter-trial interval

        fixkreuz_neutral = visual.ImageStim(win=win, name="fixcross", pos=(0, 0), image="fixkreuz.png", depth=-1)

        background.setAutoDraw(True)
        fixkreuz_neutral.setAutoDraw(True) #draw background and fix cross

        win.flip()
        

        timer.reset() #timer for presentation timing
        t = timer.getTime()


        fixkreuz_neutral.setAutoDraw(False) # fix cross disappears
        win.flip()
        central_bar.setAutoDraw(True) # draw central bar
        core.wait(0.2) # need to present bar for 200 ms
        win.flip()
        central_bar.setAutoDraw(False) #remove bar 
        win.flip()
        fixkreuz_neutral.setAutoDraw(True) # do not remove  fixcross
        win.flip()

        event.waitKeys(keyList=["left", "right"])
        filename = str(this_stimuli.file_path)
        video_stimulus = visual.MovieStim3(win=win, filename=filename, size=[320,240], pos=this_stimuli.position, flipVert=False, flipHoriz=False, loop=False,
                                            noAudio=True, fps = 30)
        while video_stimulus.status !=constants.FINISHED: #this loop will keep the playing the movie until it finishes
            video_stimulus.draw()
            win.flip()
            if p_port is not None: 
                win.callOnFlip(p_port.setData, this_stimuli.trigger)    # send trigger with image flip
            win.flip()

        timer.reset()
        t = timer.getTime()
        # same as fixcross
        while t < local_settings.minPeripheralDuration: #minimum presentation duration
            t = timer.getTime()

        fixkreuz_neutral.setAutoDraw(False)
        win.flip()

I am very grateful for every advice I can get. :slight_smile:

Best,
Laura

Not sure what is happening, but these are the steps I would take to investigate a little further:

  • Put a print statement in the while loop that plays the video to check that something is actually happening in the while loop
  • Use the default position for the MovieStim (i.e., don’t specify the pos argument)

Thank you, I will try those and see if it works. :slight_smile: Today my supervisor also mentioned that it might be related to the eyelink code which is included. I will come back here to tell which solution I found.

Hi,

I tested what you suggested, that is what was printed:

ID: LM
Tp: v
displayAPI: Connecting
Failed to load audio: setSound: could not find a sound file named type.wav
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
-1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
-1

Apart from that, leaving the position as the default did not change anything. My supervisor also mentioned about some conflict between pylink and MovieStim3. I tried briefly showing the video with cv2 and it worked, however, it does not offer the settings would be ideal for the video presentation.

Would you have any suggestions regarding that?

Thank you for the help!

Do you have the code that you use to show the video completely separately?

I also just noticed that there are two win.flip() instructions within the while loop. Could you try to remove the second one to see what happens?

Hi, sorry for taking some time. Fortunately today I found out what was happening. In the script, we defined the background using the function:

background = visual.Rect(win=win, name='background', size=(3840, 2160), ori=0, pos=(0,0), lineWidth=1,
                         lineColor=(0.8111, 0.8111, 0.8111), lineColorSpace='rgb', fillColor=(0.8111, 0.8111, 0.8111),
                         fillColorSpace='rgb', opacity=1, depth=0.0, interpolate=True) #define screen as a rectangle (fudge)
background.setAutoDraw(True) #draw screen

However, the background.setAutoDraw(True) part was throwing the video behind the window. That is why it was working, but I could not see the video. This is good to pay attention too, because it only happened to the video, but not to the images.

Thanks for the help! :slight_smile: