No sound after first trial

URL of experiment:
https://pavlovia.org/probert/deep_music_bhv_debug
https://gitlab.pavlovia.org/probert/deep_music_bhv_debug

Description of the problem:

Hello,

I’m having an issue with an online experiment that involves playing sounds (music pieces).
I have isolated the part that doesn’t work as intended, you can find it with the links above.

I have a trial routine that plays music pieces of variable length, a condition file with the file names and durations, and a loop that is supposed to play one piece at each iteration.
Everything is working properly during the first trial, but I don’t have sound for the following trials.

Some additional info :

  • I use the builder v2023.1.1 with some added JS code, and I test everything on pavlovia directly.
  • the duration is retrieved correctly.
    Duration values are always 0.5 sec more that the .mp3 durations, to make sure that the sound is not cut before the end. I have also added another 1 sec to the trial duration, just in case.
  • the file_name is also retrieved correctly.
  • the music.play() and music.stop() seem to be accessed properly
  • the music.status is correctly set at STARTED or FINISHED, during and at the end of a trial
  • I tested it on chrome & firefox, and on two computers, and I have the same issue
  • I have tried many workarounds (like setting music.stop() from custom code if t > duration), without success

The only clue that I have is this warning : “An AudioContext could not start automatically. It must be created or resumed after a user gesture on the page.”
I got it when testing on a second computer (and with chrome), but I don’t know what to do about it.

Any help would be greatly appreciated !

After a few headaches, I have found a very ugly (but working!) workaround.

In the trial where the music is played, I added a snippet of JS script (in the “end routine” tab) :

//redefine music object
music = new sound.Sound({
win: psychoJS.window,
value: 'A',
secs: (- 1),
});
music.setVolume(1.0);

It just reinitialises the music object at the end of each iteration of the loop, exactly as it is instantiated before the experiment. Now, I have sound at each iteration.

There is probably still something to fix somewhere, but at least, I got the experiment to run as intended.

1 Like

Thank you for sharing this solution. I used to solve issues described here where the original solution (starting the sound at 0.1) did not work.