mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-10 19:20:55 +00:00
make webaudio optional #508
This commit is contained in:
parent
7fa09da61f
commit
f3d5a5043d
@ -308,6 +308,7 @@ show_preload_progress_bar | boolean | If true, then a progress bar is displayed
|
||||
preload_audio | array | An array of audio files to preload before starting the experiment.
|
||||
preload_images | array | An array of image files to preload before starting the experiment.
|
||||
max_load_time | numeric | The maximum number of milliseconds to wait for content to preload. If the wait time is exceeded an error message is displayed and the experiment stops. The default value is 60 seconds.
|
||||
use_webaudio | boolean | If false, then jsPsych will not attempt to use the WebAudio API for audio playback. Instead, HTML5 Audio objects will be used. The WebAudio API offers more precise control over the timing of audio events, and should be used when possible. The default value is true.
|
||||
default_iti | numeric | The default inter-trial interval in ms. The default value if none is specified is 0ms.
|
||||
|
||||
Possible values for the exclusions parameter above.
|
||||
|
@ -28,6 +28,7 @@
|
||||
|
||||
jsPsych.init({
|
||||
timeline: timeline,
|
||||
use_webaudio: false,
|
||||
on_finish: function(){jsPsych.data.displayData();}
|
||||
});
|
||||
|
||||
|
@ -32,6 +32,7 @@
|
||||
|
||||
jsPsych.init({
|
||||
timeline: [trial_1, trial_2, trial_3],
|
||||
use_webaudio: false,
|
||||
on_finish: function() {
|
||||
jsPsych.data.displayData();
|
||||
},
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
jsPsych.init({
|
||||
timeline: [trial_1],
|
||||
use_webaudio: false,
|
||||
on_finish: function() {
|
||||
jsPsych.data.displayData();
|
||||
},
|
||||
|
11
jspsych.js
11
jspsych.js
@ -77,6 +77,7 @@ window.jsPsych = (function() {
|
||||
},
|
||||
'preload_images': [],
|
||||
'preload_audio': [],
|
||||
'use_webaudio': true,
|
||||
'exclusions': {},
|
||||
'show_progress_bar': false,
|
||||
'auto_update_progress_bar': true,
|
||||
@ -138,6 +139,9 @@ window.jsPsych = (function() {
|
||||
timeline: opts.timeline
|
||||
});
|
||||
|
||||
// initialize audio context based on options and browser capabilities
|
||||
jsPsych.pluginAPI.initAudio();
|
||||
|
||||
// below code resets event listeners that may have lingered from
|
||||
// a previous incomplete experiment loaded in same DOM.
|
||||
jsPsych.pluginAPI.reset(opts.display_element);
|
||||
@ -2097,15 +2101,18 @@ jsPsych.pluginAPI = (function() {
|
||||
}
|
||||
|
||||
// audio //
|
||||
var context = null;
|
||||
var audio_buffers = [];
|
||||
|
||||
module.initAudio = function(){
|
||||
// temporary patch for Safari
|
||||
if (typeof window !== 'undefined' && window.hasOwnProperty('webkitAudioContext') && !window.hasOwnProperty('AudioContext')) {
|
||||
window.AudioContext = webkitAudioContext;
|
||||
}
|
||||
// end patch
|
||||
|
||||
var context = (typeof window !== 'undefined' && typeof window.AudioContext !== 'undefined') ? new AudioContext() : null;
|
||||
var audio_buffers = [];
|
||||
context = (typeof window !== 'undefined' && typeof window.AudioContext !== 'undefined' && jsPsych.initSettings().use_webaudio == true) ? new AudioContext() : null;
|
||||
}
|
||||
|
||||
module.audioContext = function(){
|
||||
return context;
|
||||
|
Loading…
Reference in New Issue
Block a user