From 2d303083a00dc6ea5a43de458fd75b18acce52b4 Mon Sep 17 00:00:00 2001 From: Honey Date: Thu, 28 May 2026 01:04:16 +0200 Subject: [PATCH] fix: NP overlay still shows stale song on auto-advance MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two fixes: 1. Remove snapshot read from openNowPlaying() — the MediaController snapshot can show the old song at the old index (both still valid entries in the queue), so the ID check does not detect staleness; after the onTrackChanged fix S.qIdx is always authoritative so there is no need to read the snapshot 2. Call syncNowPlaying() explicitly in onTrackChanged so the NP overlay is refreshed immediately when the song changes while it is already open Co-Authored-By: Claude Sonnet 4.6 --- src/nowplaying.js | 15 --------------- src/player.js | 3 ++- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/src/nowplaying.js b/src/nowplaying.js index d591e67..b37e3b2 100644 --- a/src/nowplaying.js +++ b/src/nowplaying.js @@ -8,21 +8,6 @@ import { openPlModal, showSongInfo } from './ui.js'; // ─── NOW PLAYING OVERLAY ─── export function openNowPlaying() { - // On Android, verify the snapshot index before using it — the MediaController - // snapshot can lag behind ExoPlayer by one track on auto-advance. Only accept - // it when the song ID at that position matches (i.e. snapshot is not stale). - if (typeof window.NSBridge !== 'undefined') { - try { - const state = JSON.parse(window.NSBridge.getState() || '{}'); - const snapIdx = state.currentIndex; - const snapId = state.currentId || ''; - if (typeof snapIdx === 'number' && snapIdx >= 0 && snapIdx < S.queue.length) { - const expected = S.queue[snapIdx]; - if (!snapId || !expected?.id || String(snapId) === String(expected.id)) - S.qIdx = snapIdx; - } - } catch {} - } S.npOpen = true; const overlay = document.getElementById('np-overlay'); overlay.classList.add('open'); diff --git a/src/player.js b/src/player.js index dd8a8a0..cc4e30c 100644 --- a/src/player.js +++ b/src/player.js @@ -3,7 +3,7 @@ import { esc, formatDur, toast } from './utils.js'; import { api, streamUrl, coverUrl, downloadUrl, dispTitle, dispArtist, dispArtistParts, dispAlbum } from './api.js'; // views.js/ui.js circular imports — safe (only used inside function bodies) import { loadRecommendations } from './views.js'; -import { updateLyricsHighlight, onNpSongChange } from './nowplaying.js'; +import { updateLyricsHighlight, onNpSongChange, syncNowPlaying } from './nowplaying.js'; // ─── NATIVE BRIDGE DETECTION ─────────────────────────────────────────────── // True when running inside the NovaSonic Android wrapper (NSBridge injected before loadUrl). @@ -203,6 +203,7 @@ window.NSPlayer = { const s = S.queue[S.qIdx]; if (!s) return; updatePlayerUI(s, true); + syncNowPlaying(); onNpSongChange(s.id); if (indexChanged) renderQueue(); // Schedule scrobble — fires after 12s of uninterrupted playback.