Description of the problem:
I found out about being able to load resources as needed. This seems like a solution to the problem of not wanting the participant to load every wav file they might need to hear before starting the experiment.
When I load the resource noise.wav from the html folder at the head of the program, it plays. But when I load it on the fly using downloadResources, it gives me the error,
Unfortunately we encountered the following error:
when finding a player for the sound
could not find an appropriate player.
Try to run the experiment again. If the error persists, contact the experiment designer.
Ok, I finally fixed it. I think the task was going on before the loading finished. My fix was to load the sound file during the previous routine, which lasts for 5+ seconds and apparently leaves enough time for the file to load.
I was wrong. The fixed that actually fixed it was changing to the command
psychoJS._serverManager.downloadResources
rather than psychoJS.downloadResources. I think thereās a problem with the source code defining psychoJS.downloadResources? Maybe a missing underscore? Iām just learning javascript, so Iām not sure.
Iād like to suppress downloading all the resources at the beginning of the experiment and then download the set of 7 wav files I actually need during the experiment.
Iād like to be able to do this via code components rather than editing the js files directly.
Hi Wakefield,
Iām still a little confused about this, but it looks like everything in the html/resources folder is automatically downloaded (unless you change the js code), and everything else is ignored. If you then insert
psychoJS._serverManager.downloadResources([
{ name: [filename], path: [filename+(path relative to html folder) OR (web address)] }
]);
at the beginning of a routine, you can use the file [filename] after that. BUTā¦ Iāve been pulling files from another website, and it takes time to get the file, and the code does not wait for the file to load, so there needs to be a sufficient delay between the download call and the use of the file.
Thatās all Iāve figured out so far.
Thanks for your help earlier, hope Iām being helpful here!
Jon
PS. Now Iām not sure thereās actually a problem with the regular psychoJS.downloadResources command ā I think it was just a problem with it blocking as described here:
But now that Iāve got it working, Iāll just stick with psychoJS._serverManager.downloadResources. Call me superstitious.
I first tried to put the images in a sub folder from the Python code and used ā¦/Nim-Face-Stimuli/01F_HA_O.jpg but then I thought that maybe the files have to be in the html folder or below it.
I get an unknown resource error:
when setting the image of ImageStim: images
when getting the value of resource: Nim-Face-Stimuli/01F_HA_O.jpg
Do I need to specify each file in the psychoJS.downloadResources()?
Or is there any easy way to load all the files listed in a specific column of a .csv file.
If you load the contents of your csv intro arrays or a Trial Handler then you could set up a loop to append dictionary entries so you can use downloadResources. The code youāve written looks like itās asking PsychoJS to download the csv file, not things references in it.
A little addition to the approach above, since Iāll point @Zhaleh to this thread. A nice way of checking whether a resource has been downloaded is as followed:
Step 1. Have a routine for downloading resources, maybe add a text like āOne moment pleaseā to keep your participant informed.
Step 2. Add a code component.
Step 2a. In the begin routine tab of that code component, call PsychoJS to download the resource. For example:
Step 2b. In the each frame tab, keep checking whether the sound has downloaded. Once it does, finish the routine, and you can use the sound in a successive routine. Below we use the following trick: if psychoJS.serverManager.getResource('my_sound.mp3') does not throw an error, the resource is available.