]> git.mdlowis.com Git - proto/atv.git/commitdiff
fixed blinking on player when enqueueing new items
authorMike Lowis <mike.lowis@gentex.com>
Mon, 26 Feb 2024 17:46:59 +0000 (12:46 -0500)
committerMike Lowis <mike.lowis@gentex.com>
Mon, 26 Feb 2024 17:46:59 +0000 (12:46 -0500)
atv/assets/index.html

index d65446b4e6d2f48c94aaa97eb7314b60a18a890d..691d8c7a8ab0d13d3c83bae052c2492c1dd24cbd 100644 (file)
@@ -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();
     };