From db5972f57940c45bd53860625d34ba4f021c8317 Mon Sep 17 00:00:00 2001 From: Mike Lowis Date: Mon, 26 Feb 2024 12:46:59 -0500 Subject: [PATCH] fixed blinking on player when enqueueing new items --- atv/assets/index.html | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) 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(); }; -- 2.55.0