Coding for Movie Stimulus doesn't work with latest version

Hello,

Back in 2019, I found some great help from the forum for a coding issue with a movie stimulus. However, that coding which still works in version 3.1.5 does not work in the latest version of PsychoPy. Due to the pandemic, the study may have to get moved online for data collection which is why I would like to make it work with the newest version. The movie still plays however when I press ‘p’, nothing happens. The movie doesn’t stop playing and the polygon does not appear. If anyone can share some insight on how to make the coding compatible, it would be much appreciated. I have provided my coding below, it is used for ‘Each Frame.’

from psychopy.constants import (PLAYING, PAUSED)
from psychopy import prefs
prefs.hardware[‘audioLib’] = [‘sounddevice’]

videopath = r’.\GregTed.mp4’
videopath = os.path.join(os.getcwd(), videopath)
if not os.path.exists(videopath):
raise RuntimeError(“Video File could not be found:” + videopath)

Check for action keys…

for key in event.getKeys():
if key in [‘escape’, ]:
win.close()
core.quit()
elif key in [‘p’]:
if mov.status == PLAYING:
print(‘PAUSING’)
polygon.setAutoDraw(True)
mov.pause()
win.flip()
elif mov.status == PAUSED:
print(‘UN-PAUSING’)
mov.play()
polygon.setAutoDraw(False)

I think I use

key = event.getKeys()
if ‘escape’ in key:

Hello,

I tried to change the syntax to your suggestion, but it gives me a syntax error for that line and when I used it for the ‘p’ key, it said this in the Runner.
28.7303 WARNING Got keycode {} but that code isn’t yet known
28.7303 WARNING Keypress was given unknown key code (174)

The syntax error is probably due to the use of smart quotes instead of dumb. Try retyping the quotes.

Here is the new syntax. I may not have completely understood what you meant. Unfortunately, I could not change the first ‘for’ line as it would give a syntax error.

# Check for action keys.....
for key in event.getKeys():
    if ['escape', ] in key:
        win.close()
        core.quit()
    if ['p'] in key:
        if mov.status == PLAYING:
            print('PAUSING')
            polygon.setAutoDraw(True)
            mov.pause()
            win.flip()
        elif mov.status == PAUSED:
            print('UN-PAUSING')
            mov.play()
            polygon.setAutoDraw(False)