diff --git a/src/player.js b/src/player.js index 91d59fd..1c997f0 100644 --- a/src/player.js +++ b/src/player.js @@ -160,7 +160,8 @@ window.NSPlayer = { navigator.mediaSession.playbackState = state.isPlaying ? 'playing' : 'paused'; // Safety net: when playback starts, verify JS is showing the correct track. // Catches any edge cases where onTrackChanged was missed or queue drifted. - if (state.isPlaying) { + // Skip during _skipping window: snapshot may lag and still report the OLD index. + if (state.isPlaying && !_skipping) { try { const live = JSON.parse(window.NSBridge.getState() || '{}'); const liveIdx = live.currentIndex; @@ -225,7 +226,9 @@ window.NSPlayer = { // Every 8 ticks (~2 s): verify JS track matches native snapshot. // Catches the gap between auto-advance and onTrackChanged arriving in JS // (evaluateJavascript is deferred while WebView is backgrounded/resuming). - if (HAS_BRIDGE && ++_reconTick >= 8) { + // During _skipping window snapshot is stale — reset counter and wait. + if (_skipping) { _reconTick = 0; } + else if (HAS_BRIDGE && ++_reconTick >= 8) { _reconTick = 0; try { const snap = JSON.parse(window.NSBridge.getState() || '{}'); @@ -658,7 +661,8 @@ function _computeNextIdx() { } function _setSkipping() { - _skipping = true; + _skipping = true; + _reconTick = 0; clearTimeout(_skipTimer); _skipTimer = setTimeout(() => { _skipping = false; }, 2000); }