Trouble Translating Python to JavaScript

URL of experiment: Exp0Practice-ps-morrison-R2 [PsychoPy]

Hello,
I have been having trouble trying to get a previously working experiment to work properly on Pavlovia. Everything works except for the pause/play function and I believe it has something to do with the translation from Python to Javascript.

Here is my original python script that was placed under ‘Each Frame’:

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) 

Here is how PsychoPy translates it when I use ‘Auto → JS’:

import {prefs} from 'psychopy';
var _pj;
var videopath;
function _pj_snippets(container) {
    function in_es6(left, right) {
        if (((right instanceof Array) || ((typeof right) === "string"))) {
            return (right.indexOf(left) > (- 1));
        } else {
            if (((right instanceof Map) || (right instanceof Set) || (right instanceof WeakMap) || (right instanceof WeakSet))) {
                return right.has(left);
            } else {
                return (left in right);
            }
        }
    }
    container["in_es6"] = in_es6;
    return container;
}
_pj = {};
_pj_snippets(_pj);
prefs.hardware["audioLib"] = ["sounddevice"];
videopath = ".\\GregTed.mp4";
videopath = os.path.join(os.getcwd(), videopath);
if ((! os.path.exists(videopath))) {
    throw new RuntimeError(("Video File could not be found:" + videopath));
}
for (var key, _pj_c = 0, _pj_a = psychoJS.eventManager.getKeys(), _pj_b = _pj_a.length; (_pj_c < _pj_b); _pj_c += 1) {
    key = _pj_a[_pj_c];
    if (_pj.in_es6(key, ["escape"])) {
        psychoJS.window.close();
        core.quit();
    } else {
        if (_pj.in_es6(key, ["p"])) {
            if ((mov.status === PLAYING)) {
                console.log("PAUSING");
                polygon.setAutoDraw(true);
                mov.pause();
                psychoJS.window.flip();
            } else {
                if ((mov.status === PAUSED)) {
                    console.log("UN-PAUSING");
                    mov.play();
                    polygon.setAutoDraw(false);
                }
            }
        }
    }
}

Any insight on how to fix this issue would be much appreciated!

Please look at my crib sheet.

You can’t import Python libraries online.

Thank you very much! I was able to remove some of the coding that was unnecessary and added in ’ event=psychoJS.eventManager;’ into the ‘Begin Experiment’ section of my first routine which got the play/pause function to work.

However, I have now a separate issue where Pavlovia is giving me the ‘Unknown Resource’ error that you addressed in your crib sheet. All of my resources are in the html/resources folder and in the online subfolder under ‘Experiment Settings’ in the Builder. I had this issue before and it went away when I deleted the experiment in gitlab and reuploaded it but that didn’t solve the issue this time. I am working with the latest version of PsychoPy now and the loading resources bar doesn’t show up on Pavlovia even though it all worked before when I was using an older version of PsychoPy.

Would you happen to know why else this error occurs?