Update to jspsych@6.3
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
/**
|
||||
* jspsych-audio-sequence-button-response
|
||||
* Etienne Gaudrain <etienne.gaudrain@cnrs.fr>
|
||||
* jspsych-audio-sequence-button-response for jsPsych v6.3
|
||||
* Etienne Gaudrain <etienne.gaudrain@cnrs.fr> 2021-10-15
|
||||
*
|
||||
* Plugin for playing a sequence of audio files and getting an HTML button response
|
||||
*
|
||||
* Based on jspsych-audio-button-response.
|
||||
*
|
||||
* 2022-03-19: Fixed bug that ISI was applied also to last item.
|
||||
**/
|
||||
|
||||
jsPsych.plugins["audio-sequence-button-response"] = (function() {
|
||||
@@ -103,11 +105,7 @@ jsPsych.plugins["audio-sequence-button-response"] = (function() {
|
||||
plugin.trial = function(display_element, trial) {
|
||||
|
||||
var context = jsPsych.pluginAPI.audioContext();
|
||||
if(context !== null) {
|
||||
var source;
|
||||
} else {
|
||||
var audio;
|
||||
}
|
||||
var audio;
|
||||
|
||||
if(trial.visual_feedback===true && trial.i_correct===null)
|
||||
throw "'i_correct' has to be defined if visual feedback is requested.";
|
||||
@@ -125,12 +123,6 @@ jsPsych.plugins["audio-sequence-button-response"] = (function() {
|
||||
play_next_audio.i = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
// We un-highlight the previous button
|
||||
if(play_next_audio.i>0)
|
||||
$(display_element).find('#jspsych-audio-sequence-button-response-' + (play_next_audio.i-1) +' button').toggleClass('highlighted');
|
||||
*/
|
||||
|
||||
// Is it the last stimulus, do we need to end trial?
|
||||
if(play_next_audio.i >= trial.stimuli.length) {
|
||||
$(display_element).find(".jspsych-audio-sequence-button-response button").removeClass("disabled").prop('disabled', false);
|
||||
@@ -141,34 +133,37 @@ jsPsych.plugins["audio-sequence-button-response"] = (function() {
|
||||
}
|
||||
|
||||
// Prepare the next sound to play
|
||||
if(context !== null) {
|
||||
source = context.createBufferSource();
|
||||
source.buffer = jsPsych.pluginAPI.getAudioBuffer(trial.stimuli[play_next_audio.i]);
|
||||
source.connect(context.destination);
|
||||
source.onended = function(){
|
||||
jsPsych.pluginAPI.getAudioBuffer(trial.stimuli[play_next_audio.i]).then(function(buffer){
|
||||
if(context !== null) {
|
||||
audio = context.createBufferSource();
|
||||
audio.buffer = buffer;
|
||||
audio.connect(context.destination);
|
||||
} else {
|
||||
audio = buffer;
|
||||
audio.currentTime = 0;
|
||||
}
|
||||
audio.addEventListener('ended', function _audio_ended(){
|
||||
$(display_element).find('.jspsych-audio-sequence-button-response button.highlighted').removeClass('highlighted');
|
||||
setTimeout(play_next_audio, trial.isi);
|
||||
};
|
||||
} else {
|
||||
audio = jsPsych.pluginAPI.getAudioBuffer(trial.stimuli[play_next_audio.i]);
|
||||
audio.currentTime = 0;
|
||||
audio.addEventListener('ended', function(){
|
||||
$(display_element).find('.jspsych-audio-sequence-button-response button.highlighted').removeClass('highlighted');
|
||||
setTimeout(play_next_audio, trial.isi);
|
||||
if(play_next_audio.i<trial.stimuli.length){
|
||||
setTimeout(play_next_audio, trial.isi);
|
||||
} else {
|
||||
setTimeout(play_next_audio, 0);
|
||||
}
|
||||
audio.removeEventListener('ended', _audio_ended);
|
||||
});
|
||||
}
|
||||
|
||||
// Highlight the current button
|
||||
$(display_element).find('#jspsych-audio-sequence-button-response-' + play_next_audio.i +' button').addClass('highlighted');
|
||||
// Highlight the current button
|
||||
$(display_element).find('#jspsych-audio-sequence-button-response-' + play_next_audio.i +' button').addClass('highlighted');
|
||||
|
||||
if(context !== null) {
|
||||
startTime = context.currentTime;
|
||||
source.start(startTime);
|
||||
} else {
|
||||
audio.play();
|
||||
}
|
||||
if(context !== null) {
|
||||
startTime = context.currentTime;
|
||||
audio.start(startTime);
|
||||
} else {
|
||||
audio.play();
|
||||
}
|
||||
|
||||
play_next_audio.i++;
|
||||
play_next_audio.i++;
|
||||
});
|
||||
}
|
||||
|
||||
//display buttons
|
||||
@@ -288,12 +283,11 @@ jsPsych.plugins["audio-sequence-button-response"] = (function() {
|
||||
// stop the audio file if it is playing
|
||||
// remove end event listeners if they exist
|
||||
if(context !== null) {
|
||||
source.stop();
|
||||
source.onended = function() {}
|
||||
audio.stop();
|
||||
} else {
|
||||
audio.pause();
|
||||
audio.removeEventListener('ended', end_trial);
|
||||
}
|
||||
audio.removeEventListener('ended', end_trial);
|
||||
|
||||
// kill any remaining setTimeout handlers
|
||||
jsPsych.pluginAPI.clearAllTimeouts();
|
||||
|
||||
Reference in New Issue
Block a user