Skip to content

Commit

Permalink
Revert "require all images be pre-loaded before displaying in exp-loo…
Browse files Browse the repository at this point in the history
…kit-image-audio - addresses #206"

This reverts commit 18ac36c.
  • Loading branch information
Kim Scott committed Apr 14, 2021
1 parent c33a489 commit 23271fc
Showing 1 changed file with 7 additions and 40 deletions.
47 changes: 7 additions & 40 deletions app/components/exp-lookit-images-audio/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,18 +262,14 @@ export default ExpFrameBaseComponent.extend(VideoRecord, PauseUnpause, ExpandAss
}
},

recordingStarted: false,

// Override to do a bit extra when starting recording
onRecordingStarted() {
this.set('recordingStarted', true);
this.startTrialIfReady();
this.startTrial();
},

// Override to do a bit extra when starting session recorder
onSessionRecordingStarted() {
this.set('recordingStarted', true);
this.startTrialIfReady();
this.startTrial();
$('#waitForVideo').hide();
},

Expand Down Expand Up @@ -625,22 +621,12 @@ export default ExpFrameBaseComponent.extend(VideoRecord, PauseUnpause, ExpandAss
}
},

startTrialIfReady() {
let recordingNeeded = this.get('doRecording') || this.get('startSessionRecording');
let nImages = this.get('images_parsed').length;
if ((this.get('recordingStarted') || !recordingNeeded) && this.get('image_loaded_count') >= nImages && !this.get('_isPaused')) {
this.startTrial();
}
},

image_loaded_count: 0,

// Supply image IDs if they're missing.
didReceiveAttrs() {
this._super(...arguments);
// Supply image IDs if they're missing.
var N = 1;
var allImageIds = this.get('images') ? this.get('images').map(im => im.hasOwnProperty('id') ? im.id : null) : [];
$.each(this.get('images'), function (idx, image) {
var allImageIds = this.get('images') ? this.get('images').map(im => im.hasOwnProperty('id') ? im.id : null) : [];
$.each(this.get('images'), function(idx, image) {
if (!image.hasOwnProperty('id')) {
while (allImageIds.includes(`image_${N}`)) {
N++;
Expand All @@ -660,24 +646,6 @@ export default ExpFrameBaseComponent.extend(VideoRecord, PauseUnpause, ExpandAss
if (audioSources && audioSources.length) {
this.set('audioPlayed', audioSources[0].src);
}

// Preload images
let _this = this;
$.each(this.get('images_parsed'),
function (idx, obj) {
let url = obj.src;
let img = new Image();
img.onload = function () { // set onload fn before source to ensure we catch it
_this.set('image_loaded_count', _this.get('image_loaded_count') + 1);
_this.startTrialIfReady();
};
img.onerror = function () {
_this.set('image_loaded_count', _this.get('image_loaded_count') + 1);
_this.startTrialIfReady();
console.error('Unable to load image at ', url, ' - will skip loading but this may cause the exp-lookit-images-audio frame to fail');
};
img.src = url;
});
},

didInsertElement() {
Expand Down Expand Up @@ -719,8 +687,7 @@ export default ExpFrameBaseComponent.extend(VideoRecord, PauseUnpause, ExpandAss
$('#nextbutton').prop('disabled', true);

// Begin trial!
this.startTrialIfReady();
this.checkAndEnableProceed(); // Move on to next frame if nothing to do here
this.checkAndEnableProceed();
},

onStudyPause() {
Expand Down Expand Up @@ -756,7 +723,7 @@ export default ExpFrameBaseComponent.extend(VideoRecord, PauseUnpause, ExpandAss
$('.story-image-container').hide();
// If recording, trial will be started upon recording start. Otherwise...
if (!this.get('doRecording') && !this.get('startSessionRecording')) {
this.startTrialIfReady();
this.startTrial();
}
}
},
Expand Down

0 comments on commit 23271fc

Please sign in to comment.