From 0cc69e0854eb59fe2de3131e42d9b45d88fb870f Mon Sep 17 00:00:00 2001 From: Josh de Leeuw Date: Mon, 22 Nov 2021 14:39:16 -0500 Subject: [PATCH] add parameter to store audio url; release it if not stored --- .../plugin-html-audio-response/src/index.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/packages/plugin-html-audio-response/src/index.ts b/packages/plugin-html-audio-response/src/index.ts index 31f389a2..c08ccefb 100644 --- a/packages/plugin-html-audio-response/src/index.ts +++ b/packages/plugin-html-audio-response/src/index.ts @@ -29,6 +29,10 @@ const info = { type: ParameterType.BOOL, default: false, }, + store_audio_url: { + type: ParameterType.BOOL, + default: false, + }, }, }; @@ -165,7 +169,11 @@ class HtmlAudioResponsePlugin implements JsPsychPlugin { `; - display_element.querySelector("#record-again").addEventListener("click", this.startRecording); + display_element.querySelector("#record-again").addEventListener("click", () => { + // release object url to save memory + URL.revokeObjectURL(this.audio_url); + this.startRecording(); + }); display_element.querySelector("#continue").addEventListener("click", () => { this.endTrial(display_element, trial); }); @@ -179,13 +187,19 @@ class HtmlAudioResponsePlugin implements JsPsychPlugin { this.jsPsych.pluginAPI.clearAllTimeouts(); // gather the data to store for the trial - var trial_data = { + var trial_data: any = { rt: this.rt, stimulus: trial.stimulus, response: this.response, estimated_stimulus_onset: Math.round(this.stimulus_start_time - this.recorder_start_time), }; + if (trial.store_audio_url) { + trial_data.audio_url = this.audio_url; + } else { + URL.revokeObjectURL(this.audio_url); + } + // clear the display display_element.innerHTML = "";