From: Mike Lowis Date: Mon, 26 Feb 2024 17:46:59 +0000 (-0500) Subject: fixed blinking on player when enqueueing new items X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=db5972f57940c45bd53860625d34ba4f021c8317;p=proto%2Fatv.git fixed blinking on player when enqueueing new items --- diff --git a/atv/assets/index.html b/atv/assets/index.html index d65446b..691d8c7 100644 --- a/atv/assets/index.html +++ b/atv/assets/index.html @@ -81,9 +81,14 @@ const updatePlayer = ()=>{ const start_time = current["start_time"]; const duration = current["curr"]["duration"]; const elapsed = Math.floor(curr_time - start_time); - if (elapsed >= 0 && elapsed < duration) + + // Check if we need to refresh the URI + const diffTooBig = Math.abs(Math.floor(Video.currentTime) - elapsed) > 3; + const srcChanged = Video.src.replace(/#t=[0-9]+$/, '') != encodeURI(document.location + current["curr"]["path"]); + + if (diffTooBig || srcChanged) { - Video.src = current["curr"]["path"] + "#t=" + Math.floor(elapsed); + Video.src = current["curr"]["path"] + "#t=" + elapsed; if (current["playing"]) { Video.play(); @@ -101,7 +106,10 @@ const connect = ()=>{ ws.onmessage = (event)=>{ const msg = JSON.parse(event.data); - current = msg; + if (msg["cmd"] == "play") + { + current = msg; + } updatePlayer(); };