# Error running loop of videos in psychopy v2024.2.4

**URL:** <https://discourse.psychopy.org/t/error-running-loop-of-videos-in-psychopy-v2024-2-4/44076>\
**Category:** Builder\
**Created:** [February 28, 2025, 11:21am UTC](https://discourse.psychopy.org/t/error-running-loop-of-videos-in-psychopy-v2024-2-4/44076 "2025-02-28T11:21:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![martha.nguyen](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/martha.nguyen/32/44472_2.png) [@martha.nguyen](https://discourse.psychopy.org/u/martha.nguyen)\
**Post date:** [February 28, 2025, 11:21am UTC](https://discourse.psychopy.org/t/error-running-loop-of-videos-in-psychopy-v2024-2-4/44076/1 "2025-02-28T11:21:24Z")

</div>

**OS** (e.g. Win10): Win 11  
**PsychoPy version** (e.g. 1.84.x): 2024.2.4  
**Standard Standalone? (y/n)** If not then what?: yes

I am trying to set a loop of 4 videos stimuli from an excel sheet to run randomly on psychopy and keep encountering this error

RuntimeError: Calling this class method requires a successful call to `load` first.  
1.3977 WARNING Monitor specification not found. Creating a temporary one…  
ioHub Server Process Completed With Code: 0  
################ Experiment ended with exit code 1 [pid:28104] #################

For this I already add a static element

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/2/e/2e3030fcef0c06d2d567ca9bb74e5df3c733db7b.png)

But it still could not run and I don’t really understand what the error really is. (I’m a complete newbie in this)

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [February 28, 2025, 12:28pm UTC](https://discourse.psychopy.org/t/error-running-loop-of-videos-in-psychopy-v2024-2-4/44076/2 "2025-02-28T12:28:12Z")

</div>

How long are your videos? Maybe try a longer static period. See also.

> [@Preloading multiple videos in builder for fMRI experiment using a static component](https://discourse.psychopy.org/t/preloading-multiple-videos-in-builder-for-fmri-experiment-using-a-static-component/30024):
>
> OS: macOS Version 10.15.7 PsychoPy version : v2022.2.1 \*\*Standard Standalone: Y \*\*What are you trying to achieve?: I am running an fMRI experiment where a trial consists of 6, 30-second videos that are randomly presented consecutively. There are 6 trials. A trial starts after a trigger is sent from the fMRI scanner. I’m finding that the start time of the first video is inconsistent between trials. I want to try preloading the videos before my trials to try and reduce the jitter between the…

> [@Error running loop of videos in psychopy v2024.2.4](https://discourse.psychopy.org/t/error-running-loop-of-videos-in-psychopy-v2024-2-4/44076):
>
> OS (e.g. Win10): Win 11 PsychoPy version (e.g. 1.84.x): 2024.2.4 Standard Standalone? (y/n) If not then what?: yes I am trying to set a loop of 4 videos stimuli from an excel sheet to run randomly on psychopy and keep encountering this error RuntimeError: Calling this class method requires a successful call to load first. 1.3977 WARNING Monitor specification not found. Creating a temporary one… ioHub Server Process Completed With Code: 0 ################ Experiment ended with ex…

> [@Newer psychopy versions causes my experiment to crash](https://discourse.psychopy.org/t/newer-psychopy-versions-causes-my-experiment-to-crash/43995):
>
> Hi there, I designed my experiment in psychopy 2022.2.4 and it worked perfectly as intended. Now that the computer in the lab has been updated to the newer version, the experiment does not work anymore - lab computer is not connected to the internet so I cannot change version of Psychopy. In my “old” experiment, this code works perfectly: main\_movie = visual.MovieStim( win, name=‘main\_movie’, filename=None, movieLib=‘ffpyplayer’, loop=False, volume=1.0, pos=(0, 0), size=1.0, units=‘pix’, …

> [@Outer loop completes full cycle on the first pass but then freezes midway through the second pass (when an inner loop is meant to start). In builder](https://discourse.psychopy.org/t/outer-loop-completes-full-cycle-on-the-first-pass-but-then-freezes-midway-through-the-second-pass-when-an-inner-loop-is-meant-to-start-in-builder/30056):
>
> OS (e.g. Win10): OS Version 10. PsychoPy version (e.g. 1.84.x): Standard Standalone? (y/n) If not then what?: What are you trying to achieve?: In my experiment, for 1 trial, I’m presenting 6 30-second videos randomly and consecutively (in Knee\_Pain\_Trial1). This is done using a code component as I preloaded the videos at the beginning of the experiment to avoid lagging. I did this using code from this forum… And what it looks like for my experiment:

---

<div class="post-metadata">

**Author:** ![martha.nguyen](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/martha.nguyen/32/44472_2.png) [@martha.nguyen](https://discourse.psychopy.org/u/martha.nguyen)\
**Post date:** [February 28, 2025, 2:59pm UTC](https://discourse.psychopy.org/t/error-running-loop-of-videos-in-psychopy-v2024-2-4/44076/3 "2025-02-28T14:59:56Z")

</div>

Thank you for your response, I figured out the solution is to change playback \> backend from ffpyplayer to vlc. But after this a new error showed up that was

UnboundLocalError: local variable ‘pracvideos’ referenced before assignment.

This is strange because no variables were dupely named so I don’t know why it showed this new error

for thisPracvid in pracvids:  
currentLoop = pracvids  
thisExp.timestampOnFlip(win, ‘thisRow.t’, format=globalClock.format)  
if thisSession is not None:  
# if running in a Session with a Liaison client, send data up to now  
thisSession.sendExperimentData()  
# abbreviate parameter names if possible (e.g. rgb = thisPracvid.rgb)  
if thisPracvid != None:  
for paramName in thisPracvid:  
globals()[paramName] = thisPracvid[paramName]

```
    # --- Prepare to start Routine "prac_vids" ---
    # create an object to store info about Routine prac_vids
    prac_vids = data.Routine(
        name='prac_vids',
        components=[fix, preload, pracvideos],
    )
    prac_vids.status = NOT_STARTED
    continueRoutine = True
    # update component parameters for each repeat
    pracvideos = visual.VlcMovieStim(
        win=win, name='pracvideos', units='',
        filename=videos,
        ori=0.0, pos=(0, 0), opacity=None,
        loop=False, anchor='center',
        size=(0.5, 0.5),
        depth=-2.0,
        )
    # store start times for prac_vids
    prac_vids.tStartRefresh = win.getFutureFlipTime(clock=globalClock)
    prac_vids.tStart = globalClock.getTime(format='float')
    prac_vids.status = STARTED
    thisExp.addData('prac_vids.started', prac_vids.tStart)
    prac_vids.maxDuration = None
    # keep track of which components have finished
    prac_vidsComponents = prac_vids.components
    for thisComponent in prac_vids.components:
        thisComponent.tStart = None
        thisComponent.tStop = None
        thisComponent.tStartRefresh = None
        thisComponent.tStopRefresh = None
        if hasattr(thisComponent, 'status'):
            thisComponent.status = NOT_STARTED

```

Is there anything I could change in this code to fix this?
