diff --git a/src/matebot/web/app.js b/src/matebot/web/app.js index fe53f36..01cc9b4 100644 --- a/src/matebot/web/app.js +++ b/src/matebot/web/app.js @@ -92,7 +92,7 @@ function renderDetail(id, shot, compareId, compare) { if (shot.video) { const holder = document.createElement("div"); holder.className = "chart-card video-card"; - holder.innerHTML = ` + holder.innerHTML = ` `; charts.appendChild(holder); VIDEO = holder.querySelector("video"); @@ -171,6 +171,7 @@ function videoFollow(time, speed) { if (VIDEO.paused) { if (VIDEO.ended || VIDEO.currentTime >= (VIDEO.duration || Infinity)) return; VIDEO.play().catch(() => {}); + return; // no drift correction until playback actually starts } const drift = VIDEO.currentTime - vt; if (Math.abs(drift) > 1) { @@ -184,6 +185,15 @@ function videoFollow(time, speed) { } } +// True while the playing video is waiting for data; the chart clock holds so +// the curves never run ahead of a buffering video. +function videoBuffering(time) { + if (!VIDEO || VIDEO.error || VIDEO.ended || VIDEO.paused) return false; + const vt = time + VIDEO_OFFSET; + if (vt < 0 || vt >= (VIDEO.duration || Infinity)) return false; + return VIDEO.readyState < 3 || VIDEO.seeking; +} + function combinedChart(parent, t, phases, S, overlay) { if (!t || t.length < 2 || typeof Chart === "undefined") return; Chart.register(window["chartjs-plugin-annotation"]); @@ -396,7 +406,7 @@ function attachPlayer(card, t, xMax, S, overlay) { function tick(ts) { if (lastTs != null) { - playT += ((ts - lastTs) / 1000) * Number($("#speed").value); + if (!videoBuffering(playT)) playT += ((ts - lastTs) / 1000) * Number($("#speed").value); if (playT >= xMax) { playT = xMax; renderAt(playT, false);