preload video + non-preloaded video ability

This commit is contained in:
andy 2018-06-30 20:45:30 +01:00
parent 22bd4961d4
commit 07cd15dbca
3 changed files with 25 additions and 12 deletions

View File

@ -13,7 +13,7 @@
type: 'video', type: 'video',
width: 600, width: 600,
start: 8, start: 8,
stop: 10, stop: 1000,
sources: ['video/sample_video.mp4'] sources: ['video/sample_video.mp4']
} }

View File

@ -2267,7 +2267,7 @@ jsPsych.pluginAPI = (function() {
var loadfn = (typeof callback_load === 'undefined') ? function() {} : callback_load; var loadfn = (typeof callback_load === 'undefined') ? function() {} : callback_load;
var finishfn = (typeof callback_complete === 'undefined') ? function() {} : callback_complete; var finishfn = (typeof callback_complete === 'undefined') ? function() {} : callback_complete;
if(images.length==0){ if(images.length === 0){
finishfn(); finishfn();
return; return;
} }
@ -2280,7 +2280,7 @@ jsPsych.pluginAPI = (function() {
img.onload = function() { img.onload = function() {
n_loaded++; n_loaded++;
loadfn(n_loaded); loadfn(n_loaded);
if (n_loaded == images.length) { if (n_loaded === images.length) {
finishfn(); finishfn();
} }
}; };
@ -2376,7 +2376,7 @@ jsPsych.pluginAPI = (function() {
// list of items to preload // list of items to preload
images = images || []; images = images || [];
audio = audio || []; audio = audio || [];
video = video || video; video = video || [];
// construct list // construct list
for (var i = 0; i < preloads.length; i++) { for (var i = 0; i < preloads.length; i++) {

View File

@ -83,12 +83,12 @@ jsPsych.plugins.video = (function() {
video_html += ' height="'+trial.height+'"' video_html += ' height="'+trial.height+'"'
} }
if(trial.autoplay){ if(trial.autoplay){
video_html += "autoplay " video_html += " autoplay "
} }
if(trial.controls){ if(trial.controls){
video_html +="controls " video_html +=" controls "
} }
video_html+=">"
var file_name = trial.sources[0]; var file_name = trial.sources[0];
@ -97,12 +97,25 @@ jsPsych.plugins.video = (function() {
video_html += trial.prompt; video_html += trial.prompt;
} }
display_element.innerHTML = video_html; var video_preload_blob = jsPsych.pluginAPI.getVideoBuffer(file_name);
if(!video_preload_blob) {
if(file_name.indexOf('?') > -1){
file_name = file_name.substring(0, file_name.indexOf('?'));
}
var type = file_name.substr(file_name.lastIndexOf('.') + 1);
type = type.toLowerCase();
video_html+='><source src="' + file_name + '" type="video/'+type+'"></video>';
display_element.innerHTML = video_html;
}
else{
video_html+=">"
display_element.innerHTML = video_html;
display_element.childNodes[0].src = video_preload_blob;
}
var video_blob = jsPsych.pluginAPI.getVideoBuffer(file_name);
if(!video_blob) throw(file_name + ' (video) not preloaded')
display_element.childNodes[0].src = video_blob;
display_element.querySelector('#jspsych-video-player').onended = function(){ display_element.querySelector('#jspsych-video-player').onended = function(){
end_trial(); end_trial();
@ -110,7 +123,7 @@ jsPsych.plugins.video = (function() {
// event handler to set timeout to end trial if video is stopped // event handler to set timeout to end trial if video is stopped
display_element.querySelector('#jspsych-video-player').onplay = function(){ display_element.querySelector('#jspsych-video-player').onplay = function(){
display_element.src = jsPsych.pluginAPI.getVideoBuffer(trial.stimulus); if(video_preload_blob)display_element.src = jsPsych.pluginAPI.getVideoBuffer(trial.stimulus);
if(trial.stop !== null){ if(trial.stop !== null){
if(trial.start == null){ if(trial.start == null){
trial.start = 0; trial.start = 0;