Unspecified Javascript Error Related to Sounds

URL of experiment: Rachel Brown / staticImgFinal · GitLab

Description of the problem:
The experiment works locally in builder (minus some images are currently missing from the local directory to save space). When I try to run on Pavlovia I get the dreaded unspecified javascript error. I get the same error in firefox and chrome, but in chrome I also get a “failed to load resource” error, but it doesn’t say which resource.

I think maybe the problem is related to feedback sounds, and I have tried to follow all the recommended do’s and don’t’s about playing sounds in psychoJS, but I still can’t find the problem (and the error gives me zero information!).

Any suggestions??

Have you added the resources via Experiment Settings / Online in Builder?

Yes, when I click “view code” and navigate to the resources folder I see all the correct files.

That’s not the same thing. They may be online, but not loaded into memory at the start of the experiment. Does the number of resources you see getting downloaded look right?

I haven’t counted the number of files, but I did notice that the list of resources which are loaded does not seem to include the sound files, only the images.

I’m trying to create another version of the experiment without the large collection of images for the main experiment, for faster debugging. I’ll post a link as soon as it’s created.

Here is the smaller version of the experiment

Have you looked at Experiment Settings / Online in Builder?

Resources that PsychoPy knows it needs are automatically loaded into memory at the start of the experiment. However, any that are defined in code or in Excel files that are themselves defined in code need to be manually added (either there or on the fly).

Ok, in the small version I just posted I’ve fixed some bugs and re-confirmed it’s running locally. Now when I load that into Pavlovia I can see that it’s definitely loading all the correct resources, but I’m still getting the same error.

Can you set it to running and post the run link here so I can take a look?

Posting the link to the gitlab allows me to see the code but I’d have to fork and create my own version to actually test it.

Here ya go
https://run.pavlovia.org/nvrbrown/staticimgtesting/html

Selected rows for practiceTrials and mainTrials should be 0:1 not 0

Does it work if you remove your sound codes?

scorrect = new Sound(‘sounds/550.mp3’);
sincorrect = new Sound(‘sounds/270.mp3’);
stimeout = new Sound(‘sounds/375.mp3’);

Personally (and I’ve put this in my crib sheet) I recommend defining sounds using components and them playing and stopping them in code.

Yes, it works if I comment out those lines. However, I had previously set it up with sounds as components but had run into the problem that components can only be played once per routine, and I would like to be able to replay the same sound every time a key is pressed. Is there a way to do that with components?

Here’s how I do it.

You could simply try switching new Sound() to new Audio()

OK! I really, really thought that was going to work, and I got very close. But then I got this error message:

Uncaught (in promise) DOMException: The media resource indicated by the src attribute or assigned media provider object was not suitable.

I tried wav files too, that also didn’t work.

Maybe I need to specify the path to the file as a URL? How do I figure out what that URL should be?

The path should be either just the name or sounds/fileName.mp3 as you had it.

However, I notice that your Python just has numbers. Have a look at my Music Box demo to see that you can play sounds online with frequencies (but not letter notes without translation).

Yes, I am just trying to play conditional feedback sounds. I’ve just looked at your music box solution and it seems like it requires that the sound lasts for the entire routine, right? That will require some significant restructuring of my experiment.

You should be able to start and stop the sound in code once it has been created. What I wasn’t able to do was change the note of a sound (setSound) within a single routine. However, since you only have three sounds you should be able to create them all and play/stop the relevant ones.