playing audio in javascript: cannot load files in the file pool
Hello OSWeb community,
We want to play two sounds simultaneously using Javascript. Sound 1 plays first and sound 2 plays 500ms later on top of sound 1.
The codes are something like the following:
var audio1 = new Audio('audiofile1.wav');
var audio2 = new Audio('audiofile2.wav');
audio1.play();
setTimeout(() => {audio2.play();}, 500);
The audio clips only play if they are placed in Users\user\AppData\Local\Temp, even though they do exist in the file pool. This is not a viable solution if the script is hosted on JATOS as the audio files need to be hosted on the server.
Perhaps in the javascript, one needs to refer to the audio files in a different way (in the file pool) than just the file names alone?
Any suggestions? (PS: coroutines with two samplers does not work and Javascript seems the way to go).
Many thanks!
Bo
Comments
Hi Bo,
would it help to specify the complete filepath to the pool? Or first retrieve to path of the pool and then use it to list items in it?
Eduard
Hi @eduard ,
Thank you for your reply! Do you happen to know the complete filepath to the pool if the experiment is implemented in OSWeb and hosted on JATOS? I don't know where to find that information.
Many thanks,
Bo
Hi Bo,
You can try this code in a javascript inline item:
I only tried it locally though. Not sure whether it would work on Jatos.
Let me know if it doesn't work.
Eduard
Hi @boyao,
Perhaps in the javascript, one needs to refer to the audio files in a different way (in the file pool) than just the file names alone?
That's right, only using file names alone definitely will not work. What you are asking for now is not officially supported and untested by me, but you could try to retrieve the location of a file using
in an inline_javascript item. In similar vein,
should provide a list with all files and their paths currently in the filepool. Again, I haven't tried this myself so you are flying dark here. It is always helpful to check the source code of osweb to get an idea of what's possible (see https://github.com/smathot/osweb/blob/1.3/src/js/osweb/classes/file_pool_store.js for the file store for instance).