6

I'm using the jspsych.js module, and when using it, I look at the console and I'm getting this error: The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on the page.

and it takes me to this lines of code:

 core.webaudio_context = (typeof window !== 'undefined' && typeof window.AudioContext !== 'undefined') ? new AudioContext() : null;

I don't get where the mistake is.

javiera
  • 85
  • 1
  • 1
  • 5

1 Answers1

2

You need to a user-events to initiate audio.

Can you check the error lines again? Probably you are trying to start audio automatically but it's not possible.

add button your page:

<button class="play">Play</button>

Then add function to use your audio source the following;

play.onclick = function() {
audioSource.start(0);
//or another function to use audio source
}
  
badcode
  • 581
  • 1
  • 9
  • 28
  • The question was about jsPsych.js but the answer is still valid. Have a "html-button-response" prior to playing sounds (or even prior to preload-ing them), and things will work nicely. – Denis Cousineau Feb 13 '23 at 20:28