From ee05998840320649fa4d36627ce43f5c9468014a Mon Sep 17 00:00:00 2001 From: Honey Date: Wed, 13 May 2026 09:42:07 +0200 Subject: [PATCH] fix: suppress transient isPlaying:false during native skip transitions Co-Authored-By: Claude Sonnet 4.6 --- src/player.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/player.js b/src/player.js index 088ac49..45c4ede 100644 --- a/src/player.js +++ b/src/player.js @@ -14,6 +14,8 @@ let _nativePos = 0; // ms let _nativePlaying = false; let _lastPositionMs = 0; // ms — set by onPositionUpdate, used for prev() decision let _lastDurationMs = 0; // ms — set by onPositionUpdate, used for seek calculations +let _skipping = false; // true briefly after a skip — suppresses the transient isPlaying:false +let _skipTimer = null; // Unified duration / position / seek helpers — use native state when available, // fall back to HTMLAudioElement when not. @@ -96,6 +98,9 @@ window.NSPlayer = { onPlaybackStateChanged(stateJson) { try { const state = JSON.parse(stateJson); + if (state.isPlaying) { _skipping = false; clearTimeout(_skipTimer); } + // Suppress the transient isPlaying:false emitted by the native player during track transitions. + if (!state.isPlaying && _skipping) return; const prev = _nativePlaying; _nativePlaying = state.isPlaying; if (state.isPlaying !== prev) { @@ -452,9 +457,16 @@ function _computeNextIdx() { return -1; } +function _setSkipping() { + _skipping = true; + clearTimeout(_skipTimer); + _skipTimer = setTimeout(() => { _skipping = false; }, 2000); +} + export function prevSong() { _clearPreload(); if (HAS_BRIDGE) { + _setSkipping(); if (_lastPositionMs > 3000) { _nsBridge('prev'); return; } if (S.qIdx > 0) { S.qIdx--; @@ -471,6 +483,7 @@ export function prevSong() { export function nextSong() { _clearPreload(); if (HAS_BRIDGE) { + _setSkipping(); const ni = _computeNextIdx(); if (ni >= 0 && ni < S.queue.length) { S.qIdx = ni;