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, default: undefined, no_function: false, description: '' }, stimulus_duration: { type: jsPsych.plugins.parameterType.INT, default: -1, no_function: false, description: '' }, min: { type: jsPsych.plugins.parameterType.INT, default: 0, no_function: false, description: '' }, max: { type: jsPsych.plugins.parameterType.INT, default: 100, no_function: false, description: '' }, step: { type: jsPsych.plugins.parameterType.INT, default: 1, no_function: false, description: '' }, button_label: { type: jsPsych.plugins.parameterType.STRING, default: 'Next', no_function: false, description: '' }, trial_duration: { type: jsPsych.plugins.parameterType.INT, default: -1, no_function: false, description: '' }, response_ends_trial: { type: jsPsych.plugins.parameterType.BOOL, default: true, no_function: false, description: '' }, trial_ends_after_audio: { type: jsPsych.plugins.parameterType.BOOL, default: false, no_function: false, description: '' }, prompt: { type: jsPsych.plugins.parameterType.STRING, default: '', no_function: false, description: '' } } } plugin.trial = function(display_element, trial) { // setup stimulus var context = jsPsych.pluginAPI.audioContext(); if(context !== null){ var source = context.createBufferSource(); source.buffer = jsPsych.pluginAPI.getAudioBuffer(trial.stimulus); source.connect(context.destination); } else { var audio = jsPsych.pluginAPI.getAudioBuffer(trial.stimulus); audio.currentTime = 0; } // set up end event if trial needs it if(trial.trial_ends_after_audio){ if(context !== null){ source.onended = function() { end_trial(); } } else { audio.addEventListener('ended', end_trial); } } var html = '