mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-10 19:20:55 +00:00
preload video + non-preloaded video ability
This commit is contained in:
parent
22bd4961d4
commit
07cd15dbca
@ -13,7 +13,7 @@
|
||||
type: 'video',
|
||||
width: 600,
|
||||
start: 8,
|
||||
stop: 10,
|
||||
stop: 1000,
|
||||
sources: ['video/sample_video.mp4']
|
||||
}
|
||||
|
||||
|
@ -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++) {
|
||||
|
@ -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+='><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(){
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user