fix: suppress transient isPlaying:false during native skip transitions
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
1e61d35018
commit
ee05998840
1 file changed
+13
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user