jsPsych.plugins['audio-slider-response'] = (function () { var plugin = {}; jsPsych.pluginAPI.registerPreload('audio-slider-response', 'stimulus', 'audio'); plugin.info = { name: 'audio-slider-response', description: '', parameters: { stimulus: { type: jsPsych.plugins.parameterType.AUDIO, pretty_name: 'Stimulus', default: undefined, description: 'The image to be displayed' }, min: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Min slider', default: 0, description: 'Sets the minimum value of the slider.' }, max: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Max slider', default: 100, description: 'Sets the maximum value of the slider', }, slider_start: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Slider starting value', default: 50, description: 'Sets the starting value of the slider', }, step: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Step', default: 1, description: 'Sets the step of the slider' }, labels: { type: jsPsych.plugins.parameterType.HTML_STRING, pretty_name: 'Labels', default: [], array: true, description: 'Labels of the slider.', }, slider_width: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Slider width', default: null, description: 'Width of the slider in pixels.' }, button_label: { type: jsPsych.plugins.parameterType.STRING, pretty_name: 'Button label', default: 'Continue', array: false, description: 'Label of the button to advance.' }, require_movement: { type: jsPsych.plugins.parameterType.BOOL, pretty_name: 'Require movement', default: false, description: 'If true, the participant will have to move the slider before continuing.' }, prompt: { type: jsPsych.plugins.parameterType.STRING, pretty_name: 'Prompt', default: null, description: 'Any content here will be displayed below the slider.' }, trial_duration: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Trial duration', default: null, description: 'How long to show the trial.' }, response_ends_trial: { type: jsPsych.plugins.parameterType.BOOL, pretty_name: 'Response ends trial', default: true, description: 'If true, trial will end when user makes a response.' }, response_allowed_while_playing: { type: jsPsych.plugins.parameterType.BOOL, pretty_name: 'Response allowed while playing', default: true, description: 'If true, then responses are allowed while the audio is playing. ' + 'If false, then the audio must finish playing before a response is accepted.' } } } plugin.trial = function (display_element, trial) { // half of the thumb width value from jspsych.css, used to adjust the label positions var half_thumb_width = 7.5; // setup stimulus var context = jsPsych.pluginAPI.audioContext(); var audio; // record webaudio context start time var startTime; // for storing data related to response var response; // load audio file jsPsych.pluginAPI.getAudioBuffer(trial.stimulus) .then(function (buffer) { if (context !== null) { audio = context.createBufferSource(); audio.buffer = buffer; audio.connect(context.destination); } else { audio = buffer; audio.currentTime = 0; } setupTrial(); }) .catch(function (err) { console.error(`Failed to load audio file "${trial.stimulus}". Try checking the file path. We recommend using the preload plugin to load audio files.`) console.error(err) }); function setupTrial() { // set up end event if trial needs it if (trial.trial_ends_after_audio) { audio.addEventListener('ended', end_trial); } // enable slider after audio ends if necessary if ((!trial.response_allowed_while_playing) & (!trial.trial_ends_after_audio)) { audio.addEventListener('ended', enable_slider); } var html = '