| Reference | Downloads | Github

Videos are not played multiple times in Pavlovia

Hi @TommasoGhilardi,

The first piece of code,; needs to be added at the Beginning of your routine, in the right panel of the Code component (javascript), as you can see here (replace “box_mov_3” with the name of your movie component):

Same thing with the other piece of code, nameOfMyMovie.stop();, which you need to add at the End of your routine.

Also (not sure if this changes anything) but set your movie component to set at every repeat


I’m having a similar issue.
I created a pilot experiment in PsychoPy v2020.1.3 in Windows10. It shows 2 short videos (~2s and ~2MB) for 3 times each.
The videos work perfectly if I run the experiment in PsychoPy but not when I run it with Pavlovia ( Pilot mode). At the second repetition of the video, it shows only the last frame.

What I did was to add in the Code component in the same Routine where the videos are. At the Begin and End Routine I wrote the name of the video column in the Excel file I specified in the trial Properties. Unfortunately, it did not solve the problem.
Do you have some additional suggestions?
Thanks a lot

Hi @mariacarlaMemeo. Not sure why it might not be working, but here are two things you could try:

  • Setting your movie component to set at every repeat .
  • The first code component; needs to be added at the Beginning of the routine, in the right panel (javascript), while the second code component nameOfMyMovie.stop(); needs to be added at the end of that same Routine.
1 Like

I’m having the same problem as @mariacarlaMemeo. Two video fragments of 2 seconds should play right after each other. So I have two movie components within the same trial. They are both set to ‘set at every repeat’ and I tried adding the code components for both movie components. If I upload this to Pavlovia, only the first movie plays.
I then tried making two code components (for each movie separately), and tried both the ‘reset’ and ‘stop’, but nothing seems to make it better.

I would really appreciate if someone could help me out.
Thank you very much!

Hi @Mardock,
thx for your reply!
I tried what you suggested one step at a time.
I did set the movie component to set at every repeat and the experiment is working in PsychoPy but not in Pavlovia.
Then, I inserted the custom code at the beginning and the end of the Routine. Here there is a picture of the structure of the whole Routine:

At the beginning it was not working even in PsychoPy, because I inserted the and nameOfMyMovie.stop() with Code Type: Auto → JS.
It started working again when I changed it as Code Type: Both.

Unfortunately, none of those are suitable solutions for Pavlovia (I commited and pushed the code from PsychoPy) and I’m still having the same issue.

Code: Sign in · GitLab

I played a bit with the JS code in PsychoPy Builder and now in Pavlovia I have the following error: TypeError: is not a function.
I displayed the entire error message in the javascript console in Chrome, below there is the relative picture:

I searched for solutions but I wasn’t able to find anything appropriate.
As far as the error states I thought that I should probably change the Code in which I added Show_vid is the name of the column in the Excel file where the name of videos are written. I tried to edit the code in the following ways:

  • $ ;
  • $Show_vid.[0].play() ;
  • $Show_vid.get().play() ;
  • $('Pouring_video.mp4')[0].play(); where Pouring_video.mp4 is the explicit name of the video;
  • $('Pouring_video.mp4')get().play();

I tried also all the previous codes without $ at the beginning. But I managed to have always the same error.
Thanks for your help

Ok, problem solved. It was a trivial issue for a beginner as I am.

What I was wrongly inserting in the custom code was the name of the excel file column with the list of the videos.
Instead the correct one is the name of the video ‘instance’ created in Psychopy, e.g. movie_randomized as you can see in the following image.

I hope it can help!

Sadly, I still haven’t found a solution. I tried playing around with the combination of multiple code snippets and their placement.
This is where I am now:
The first video plays but freezes at the last frame so the second video isn’t visible anymore. After 7 seconds the ‘text_answer’ appears on top of the frozen video.
I made the code snippets based on the information from the previous posts. (with .play(); and .stop(); ).

Maybe somebody knows what I’m doing wrong and/or how I can fix it?
Thank you!

Hi @MyrteVC ,
my final configuration of the routine is this:

For me it worked adding only one code component after the video instance (movie_randomized). I’m not sure if it is the case also with the presentation of 2 videos.

1 Like

A note on the video solution to use in the code component.
Because this goes in ‘begin routine’, it seems to start the video as soon as the routine starts whether it is onscreen or not - i.e. you may not want it to play until after a 1second fixation. so set it to start at 1, however the video will actually have already been playing for 1 second before it actually appears. This may be the problem that @MyrteVC was having.

This issue has made all my timings completely wrong, and so I hope others see this and don’t make the same mistake

@Mardock thanks a million for solving this problem before I had it, so I could use your solution! However, when using; and movie.stop(); at begin routine and end routine, respectively (and I added movie.reset(); right before the;, which didn’t make anything better or worse), my videos begin to stutter. I mean, they don’t run smoothly anymore, the way they ran before. Does anyone know why that might be? Does the play() use another player than would be used without that line or something like that?

I’m not sure what you mean by not running smoothly. I had an issue where the video started in the wrong place and quickly snapped back to the start - does this describe what you are seeing? To solve it, I just presented a brief (100ms) blank stimulus at the start of the trial which essentially covered the very start of the video, this probably didn’t remove the jitter but covered it so that it wasn’t seen by participants. The other thing would be to see if reducing the size of the video files helps. Sorry I don’t have a more technical solution.

Well, it looks like a bad internet connection in a video chat (without the blur effect). The picture sometimes hitches… it stands still for a short time and then jumps to the correct frame. So, it’s unfortunately not only at the very start of the videos. I’ll try something like a short blank stimulus as you suggested in the beginning, anyhow - maybe it’s some kind of buffering problem… I’ll report when I’ve tried! ^^

UPDATE: didn’t work

Update: I just realized that the problem seems to arise from the window size (runs smoothly on laptop screen and in small-sized browser window on second (large) screen, but hitches in large-sized browser window on large screen) and/or the browser (runs smoothly when small-sized in firefox, but always hitches in chrome) … will look for more appropriate forum posts… cheers

I have the same problem! I have two videos in each trial and text components before the first movie, between the two movies, and after the second movie. The text components are shown on top of the last frame (?) of the movies. The movies also don’t play after I played them once.

I played around with putting the code components before and after each movie, at the beginning and end of the routing, only after each movie, only at the end to stop or reset the movies. Nothing works! Putting in beginning of routine screws up the timing of my trial components, .stop() and .reset() don’t seem to do anything.

Does anyone have a solution when using two movies?

Did you find a solution to this problem, @Anne?

I think I’m having the same issue. I have three videos in my routine, separated by a picture that presents for 2 seconds. The first video plays fine, but the second and third freeze a few seconds into playing.

Hi Igunning! That sounds a little bit different than my problem…

In my experiment I have 20 pairs of videos and always show one pair in a trial. The first time I show a video pair, both videos work fine. However, the second time I show the same pair, the videos aren’t playing anymore. From what I understood it’s because the first time the videos play they are not properly reset, and that’s what they don’t play the second time. However, I couldn’t figure out how to fix this problem…I ended up copying all my videos, so I really only show each video once.

Hi all,

I had the same issue, where repeating videos in my experiment freezes the second time around. I tried the solution suggested here, inserting; at the Beginning of the Routine and nameOfMyMovie.stop(); at the end of the Routine. It didn’t work and I also tried all the different combinations suggested in the other thread regarding similar issues: None of those options also worked for me.

Finally, I used a different hack, where I pulled the durations of my videos and creating a new variable in the trial excel sheet named “time” in which each video’s corresponding duration in seconds is listed down. Then in the movie component of my routine, I set the stop duration to be $time, so that when each video play in the routine, the routine duration also matches that. Hence, even if the video end is not recognized by the pavlovia during the second run through and doesn’t force the end of the routine. The routine will still end after running for the duration equivalent to the video clip’s runtime. It was possible because I had only a few videos in my experiment, it may not be a solution for the experiments where there is a lot of videos and all of their runtimes are different!

However, still will be interested to see whether there are any alternative and better solutions!


1 Like

I have a similar problem, while the video plays the second time it appears, it no longer ends the routine. As the different videos that get inserted have different lengths I do not want to rely on a “timer”. Does anybody know how to get the video to force the end of the routine for a second time?

Hi, I have a similar problem. Although, when I add the; code snippet, Pavlovia gives the following error message:
Experiment: PILOT_NAD_signlang [PsychoPy]
Repository: MTA-BME Lendület Nyelvelsajátítás Kutatócsoport / PILOT_NAD_signlang · GitLab
(It apparently has no problem with the name_of_my_movie.stop() snippet…)
When I remove it, as expected, it freezes when videos are played for the second time.
Does anyone have any ideas how to solve this issue?

And does anyone know if this issue has been indicated to the developers? It would be nice if video files could be played without these issues and workarounds…