From 8a6b8fb5953ccfad9f9a0031ceb1bbc11b505687 Mon Sep 17 00:00:00 2001 From: Stephen Jerge Date: Wed, 19 Nov 2025 00:03:54 -0500 Subject: [PATCH] Fix WebAudio stop error on early audio-button end --- .changeset/audio-stop-bug.md | 5 +++++ contributors.md | 3 ++- packages/plugin-audio-button-response/src/index.ts | 6 +++--- 3 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 .changeset/audio-stop-bug.md diff --git a/.changeset/audio-stop-bug.md b/.changeset/audio-stop-bug.md new file mode 100644 index 0000000000..9e81266bd4 --- /dev/null +++ b/.changeset/audio-stop-bug.md @@ -0,0 +1,5 @@ +--- +"@jspsych/plugin-audio-button-response": patch +--- + +Prevent WebAudio stop error when trials end early by removing ended listeners before stopping playback. diff --git a/contributors.md b/contributors.md index 17acdf5fe0..f3712ca20c 100644 --- a/contributors.md +++ b/contributors.md @@ -28,6 +28,7 @@ The following people have contributed to the development of jsPsych by writing c * Andy Heusser - https://github.com/andrewheusser * Angus Hughes - https://github.com/awhug * jade - https://github.com/jadeddelta +* Stephen M. Jerge - https://github.com/stephenmjerge * Gustavo Juantorena - https://github.com/GEJ1 * Chris Jungerius - https://github.com/cjungerius * George Kachergis - https://github.com/kachergis @@ -72,4 +73,4 @@ The following people have contributed to the development of jsPsych by writing c * Shaobin Jiang - https://github.com/Shaobin-Jiang * Haotian Tu - https://github.com/thtTNT * Joshua Unrau - https://github.com/joshunrau -* Victor Zhang - https://github.com/vzhang03 \ No newline at end of file +* Victor Zhang - https://github.com/vzhang03 diff --git a/packages/plugin-audio-button-response/src/index.ts b/packages/plugin-audio-button-response/src/index.ts index 159dabe118..74f129e299 100644 --- a/packages/plugin-audio-button-response/src/index.ts +++ b/packages/plugin-audio-button-response/src/index.ts @@ -291,13 +291,13 @@ class AudioButtonResponsePlugin implements JsPsychPlugin { // method to end trial when it is time private end_trial = () => { - // stop the audio file if it is playing - this.audio.stop(); - // remove end event listeners if they exist this.audio.removeEventListener("ended", this.end_trial); this.audio.removeEventListener("ended", this.enable_buttons); + // stop the audio file if it is playing + this.audio.stop(); + // gather the data to store for the trial var trial_data = { rt: this.response.rt,