mirror of
https://github.com/mehotkhan/BandersnatchInteractive.git
synced 2025-07-28 09:42:55 +00:00
assets/scripts.js: Improve timer logic
Use end of ongoing moments and start of upcoming moments too.
This commit is contained in:
parent
57166f7daa
commit
39c3144e4c
1 changed files with 14 additions and 5 deletions
|
@ -220,15 +220,10 @@ function ontimeupdate(evt) {
|
||||||
var ms = getCurrentMs();
|
var ms = getCurrentMs();
|
||||||
currentSegment = getSegmentId(ms);
|
currentSegment = getSegmentId(ms);
|
||||||
|
|
||||||
// ontimeupdate resolution is about a second. Augment it using timer.
|
|
||||||
if (timerId) {
|
if (timerId) {
|
||||||
clearTimeout(timerId);
|
clearTimeout(timerId);
|
||||||
timerId = 0;
|
timerId = 0;
|
||||||
}
|
}
|
||||||
if (currentSegment && nextSegment && nextSegment != currentSegment) {
|
|
||||||
var timeLeft = segmentMap.segments[currentSegment].endTimeMs - ms;
|
|
||||||
timerId = setTimeout(ontimeupdate, timeLeft);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Distinguish between the user seeking manually with <video> controls,
|
// Distinguish between the user seeking manually with <video> controls,
|
||||||
// and the video playing normally (past some timestamp / boundary).
|
// and the video playing normally (past some timestamp / boundary).
|
||||||
|
@ -308,6 +303,20 @@ function ontimeupdate(evt) {
|
||||||
location.hash = hash;
|
location.hash = hash;
|
||||||
ls.place = hash;
|
ls.place = hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ontimeupdate resolution is about a second. Augment it using timer.
|
||||||
|
let nextEvent = segmentMap.segments[currentSegment].endTimeMs;
|
||||||
|
for (let k in currentMoments) {
|
||||||
|
let m = currentMoments[k];
|
||||||
|
if (m.endMs < nextEvent)
|
||||||
|
nextEvent = m.endMs;
|
||||||
|
}
|
||||||
|
for (let m of momentsBySegment[currentSegment] || [])
|
||||||
|
if (ms < m.startMs && m.startMs < nextEvent)
|
||||||
|
nextEvent = m.startMs;
|
||||||
|
var timeLeft = nextEvent - ms;
|
||||||
|
if (timeLeft > 0)
|
||||||
|
timerId = setTimeout(ontimeupdate, timeLeft);
|
||||||
}
|
}
|
||||||
|
|
||||||
function jumpForward() {
|
function jumpForward() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue