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 ───
|
||||
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;
|
||||
|
||||
Reference in new issue
Block a user