mirror of
https://github.com/mehotkhan/BandersnatchInteractive.git
synced 2025-07-28 01:33:23 +00:00
assets/scripts.js: Improve handling of seeking
- Don't apply impressions when the player seeks into moments with impression data - Fix false positives when seeking within the first few seconds of a segment
This commit is contained in:
parent
588036f80e
commit
b4e04bccd1
1 changed files with 19 additions and 13 deletions
|
@ -185,13 +185,14 @@ function addChoices(r) {
|
||||||
document.getElementById("choiceCaption").innerHTML = choicePoints[r.id].description;
|
document.getElementById("choiceCaption").innerHTML = choicePoints[r.id].description;
|
||||||
}
|
}
|
||||||
|
|
||||||
function momentStart(m) {
|
function momentStart(m, seeked) {
|
||||||
console.log('momentStart', m);
|
console.log('momentStart', m, seeked);
|
||||||
if (m.type == 'scene:cs_bs') {
|
if (m.type == 'scene:cs_bs') {
|
||||||
addZones(currentSegment);
|
addZones(currentSegment);
|
||||||
addChoices(m);
|
addChoices(m);
|
||||||
}
|
}
|
||||||
applyImpression(m.impressionData);
|
if (!seeked)
|
||||||
|
applyImpression(m.impressionData);
|
||||||
}
|
}
|
||||||
|
|
||||||
function momentUpdate(m, ms) {
|
function momentUpdate(m, ms) {
|
||||||
|
@ -202,8 +203,8 @@ function momentUpdate(m, ms) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function momentEnd(m) {
|
function momentEnd(m, seeked) {
|
||||||
console.log('momentEnd', m);
|
console.log('momentEnd', m, seeked);
|
||||||
if (m.type == 'scene:cs_bs') {
|
if (m.type == 'scene:cs_bs') {
|
||||||
setNextSegment(null);
|
setNextSegment(null);
|
||||||
addZones(currentSegment);
|
addZones(currentSegment);
|
||||||
|
@ -213,6 +214,7 @@ function momentEnd(m) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var timerId = 0;
|
var timerId = 0;
|
||||||
|
var lastMs = 0;
|
||||||
|
|
||||||
function ontimeupdate(evt) {
|
function ontimeupdate(evt) {
|
||||||
var ms = getCurrentMs();
|
var ms = getCurrentMs();
|
||||||
|
@ -229,30 +231,33 @@ function ontimeupdate(evt) {
|
||||||
timerId = setTimeout(ontimeupdate, timeLeft);
|
timerId = setTimeout(ontimeupdate, timeLeft);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Distinguish between the user seeking manually with <video> controls,
|
||||||
|
// and the video playing normally (past some timestamp / boundary).
|
||||||
|
let timeElapsed = ms - lastMs;
|
||||||
|
let seeked = timeElapsed >= 0 && timeElapsed < 2000;
|
||||||
|
lastMs = ms;
|
||||||
|
|
||||||
if (currentSegment != segmentId) {
|
if (currentSegment != segmentId) {
|
||||||
console.log('ontimeupdate', currentSegment, segmentId, ms, msToString(ms));
|
console.log('ontimeupdate', currentSegment, segmentId, ms, msToString(ms));
|
||||||
// Distinguish between the user seeking manually with <video> controls,
|
if (seeked) {
|
||||||
// from the video playing past the current segment end.
|
playSegment(segmentId, true);
|
||||||
if (ms > segmentMap.segments[currentSegment].endTimeMs &&
|
} else {
|
||||||
ms < segmentMap.segments[currentSegment].endTimeMs + 2000) {
|
|
||||||
// TODO: activate and apply user choice (whether or not it
|
// TODO: activate and apply user choice (whether or not it
|
||||||
// was default) instead of just playing the next segment.
|
// was default) instead of just playing the next segment.
|
||||||
playSegment(nextSegment, true);
|
playSegment(nextSegment, true);
|
||||||
} else {
|
|
||||||
playSegment(segmentId, true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var moments = getMoments(segmentId, ms);
|
var moments = getMoments(segmentId, ms);
|
||||||
for (let k in currentMoments)
|
for (let k in currentMoments)
|
||||||
if (!(k in moments))
|
if (!(k in moments))
|
||||||
momentEnd(currentMoments[k]);
|
momentEnd(currentMoments[k], seeked);
|
||||||
for (let k in currentMoments)
|
for (let k in currentMoments)
|
||||||
if (k in moments)
|
if (k in moments)
|
||||||
momentUpdate(currentMoments[k], ms);
|
momentUpdate(currentMoments[k], ms);
|
||||||
for (let k in moments)
|
for (let k in moments)
|
||||||
if (!(k in currentMoments))
|
if (!(k in currentMoments))
|
||||||
momentStart(moments[k]);
|
momentStart(moments[k], seeked);
|
||||||
currentMoments = moments;
|
currentMoments = moments;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -387,6 +392,7 @@ function seek(ms) {
|
||||||
clearTimeout(timerId);
|
clearTimeout(timerId);
|
||||||
console.log('seek', ms);
|
console.log('seek', ms);
|
||||||
momentSelected = null;
|
momentSelected = null;
|
||||||
|
lastMs = ms;
|
||||||
document.getElementById("video").currentTime = ms / 1000.0;
|
document.getElementById("video").currentTime = ms / 1000.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue