diff --git a/examples/jspsych-video.html b/examples/jspsych-video.html index 947c5fcf..5dc33782 100644 --- a/examples/jspsych-video.html +++ b/examples/jspsych-video.html @@ -13,7 +13,7 @@ type: 'video', width: 600, start: 8, - stop: 10, + stop: 1000, sources: ['video/sample_video.mp4'] } diff --git a/jspsych.js b/jspsych.js index f9601f31..47bd96a9 100755 --- a/jspsych.js +++ b/jspsych.js @@ -2267,7 +2267,7 @@ jsPsych.pluginAPI = (function() { var loadfn = (typeof callback_load === 'undefined') ? function() {} : callback_load; var finishfn = (typeof callback_complete === 'undefined') ? function() {} : callback_complete; - if(images.length==0){ + if(images.length === 0){ finishfn(); return; } @@ -2280,7 +2280,7 @@ jsPsych.pluginAPI = (function() { img.onload = function() { n_loaded++; loadfn(n_loaded); - if (n_loaded == images.length) { + if (n_loaded === images.length) { finishfn(); } }; @@ -2376,7 +2376,7 @@ jsPsych.pluginAPI = (function() { // list of items to preload images = images || []; audio = audio || []; - video = video || video; + video = video || []; // construct list for (var i = 0; i < preloads.length; i++) { diff --git a/plugins/jspsych-video.js b/plugins/jspsych-video.js index 5bdaf388..6756f945 100644 --- a/plugins/jspsych-video.js +++ b/plugins/jspsych-video.js @@ -83,12 +83,12 @@ jsPsych.plugins.video = (function() { video_html += ' height="'+trial.height+'"' } if(trial.autoplay){ - video_html += "autoplay " + video_html += " autoplay " } if(trial.controls){ - video_html +="controls " + video_html +=" controls " } - video_html+=">" + var file_name = trial.sources[0]; @@ -97,12 +97,25 @@ jsPsych.plugins.video = (function() { 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+='>'; + 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(){ end_trial(); @@ -110,7 +123,7 @@ jsPsych.plugins.video = (function() { // event handler to set timeout to end trial if video is stopped 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.start == null){ trial.start = 0;