diff --git a/src/nowplaying.js b/src/nowplaying.js index ac27f6a..d591e67 100644 --- a/src/nowplaying.js +++ b/src/nowplaying.js @@ -8,13 +8,19 @@ import { openPlModal, showSongInfo } from './ui.js'; // ─── NOW PLAYING OVERLAY ─── export function openNowPlaying() { - // On Android, onTrackChanged is async — query native for the current index - // before rendering so we never show the previous song for a flash. + // 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() || '{}'); - if (typeof state.currentIndex === 'number' && state.currentIndex >= 0 && state.currentIndex < S.queue.length) - S.qIdx = state.currentIndex; + 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;