MovieStim - Wait to play until a button is pressed

PsychoPy (v2022.2.1)

Hello :slight_smile:
I am trying to play a movie stimulus for an experiment, but I want it to start playing after I press a play button. Specifically, I want the movie to appear on the screen paused and then play after the button has been pressed. I preferably do not want a key press though.

a. The movie stimulus (VideoPres) is set to start at – time(s) 0. I do not want to use a condition (although it works), because that means the stimulus will appear when the condition is met.
b. My ‘play button’ is basically an Image with a mouse component.
c. I have a code:

Begin Routine

if VideoPres.status == PLAYING:
    VideoPres.pause()

Each Frame

if PlayMouse.isPressedIn(PlayButton):
    VideoPres.play()

What have I tried:

I tried using VideoPres.autoStart(False) and other possibilities of the VideoPres.status and functions, which I do not clearly remember right now, because I have been trying different things for the past day.

With an if/else statement, it seemed to work, but only if the mouse is being pressed continuously.

What seemed to work:

I eventually went to the python script, and changed the code here. Specifically, I changed VideoPres.play() – to – VideoPres.pause(). That worked perfectly when I was running it as a py file, but I have no idea how to run it in Pavlovia, without using the Builder. I tried syncing the file with the Pavlovia project, but when I ran it it looked like nothing was synced.

 # *VideoPres* updates
        if VideoPres.status == NOT_STARTED and tThisFlip >= 0-frameTolerance:
            # keep track of start time/frame for later
            VideoPres.frameNStart = frameN  # exact frame index
            VideoPres.tStart = t  # local t and not account for scr refresh
            VideoPres.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(VideoPres, 'tStartRefresh')  # time at next scr refresh
            # add timestamp to datafile
            thisExp.timestampOnFlip(win, 'VideoPres.started')
            VideoPres.setAutoDraw(True)
            VideoPres.pause()
        if VideoPres.status == FINISHED:  # force-end the routine
            continueRoutine = False

Any ideas/help is greatly appreciated! I have run out of options :frowning:

At present, what I think of is that you can use mouse, and then put a Button to control the video playback time by setting the time

Hey, thank you for your suggestion. That is what I am trying to do. I have a mouse and a button component. What I am trying to do is, when the button is clicked (mouse.isPressedIn(button), the video plays. I am having trouble understanding what you mean by ‘setting the time’ though?

Hi Danae! Were you able to get this to function? I’m having the same issue and would love to see how you solved this if so!

Hey :slight_smile: I ended up writing this code:

if frameN == 0:
    VideoPres.pause()
    
if PlayMouse.isPressedIn(PlayButton):
    VideoPres.play()

where VideoPres is the name of your video component, PlayMouse the name of your mouse component and PlayButton the name of your button component.

I hope this helps!