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: '' }, 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: '' }, } } plugin.trial = function(display_element, trial) { trial.min = trial.min || 0; trial.max = trial.max || 100; trial.step = trial.step || 1; trial.button_label = typeof trial.button_label === 'undefined' ? 'Next' : trial.button_label; trial.response_ends_trial = (typeof trial.response_ends_trial == 'undefined') ? true : trial.response_ends_trial; trial.trial_ends_after_audio = (typeof trial.trial_ends_after_audio === 'undefined') ? false : trial.trial_ends_after_audio; trial.stimulus_duration = trial.stimulus_duration || -1; trial.trial_duration = trial.trial_duration || -1; trial.prompt = trial.prompt || ""; // 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 = '