fix: NP overlay shows stale song on Android auto-advance
openNowPlaying() was blindly trusting the MediaController snapshot index, which can lag one track behind ExoPlayer on auto-advance. This overwrote the already-correct S.qIdx that onTrackChanged had just set, causing the NP overlay to render the previous song while the mini-player showed the right one. Now only accept the snapshot index when the song ID at that position matches — stale snapshots are silently ignored. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
9ab3dab508
commit
ba28518d8a
1 file changed
+10
-4
+10
-4
@@ -8,13 +8,19 @@ import { openPlModal, showSongInfo } from './ui.js';
|
|||||||
|
|
||||||
// ─── NOW PLAYING OVERLAY ───
|
// ─── NOW PLAYING OVERLAY ───
|
||||||
export function openNowPlaying() {
|
export function openNowPlaying() {
|
||||||
// On Android, onTrackChanged is async — query native for the current index
|
// On Android, verify the snapshot index before using it — the MediaController
|
||||||
// before rendering so we never show the previous song for a flash.
|
// 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') {
|
if (typeof window.NSBridge !== 'undefined') {
|
||||||
try {
|
try {
|
||||||
const state = JSON.parse(window.NSBridge.getState() || '{}');
|
const state = JSON.parse(window.NSBridge.getState() || '{}');
|
||||||
if (typeof state.currentIndex === 'number' && state.currentIndex >= 0 && state.currentIndex < S.queue.length)
|
const snapIdx = state.currentIndex;
|
||||||
S.qIdx = 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 {}
|
} catch {}
|
||||||
}
|
}
|
||||||
S.npOpen = true;
|
S.npOpen = true;
|
||||||
|
|||||||
Reference in new issue
Block a user