fix prev restart threshold

This commit is contained in:
Boof2015
2026-07-15 19:47:59 -04:00
parent 06c9227658
commit 89c6bac546
3 changed files with 42 additions and 0 deletions
+15
View File
@@ -26,6 +26,7 @@ import {
prepareAudioProcessingForPlayback,
primePreparedTrackForPlayback,
} from './audioProcessingStartup';
import { shouldRestartOnPrevious } from './playbackNavigation';
// If a background queue fill dies partway, the mirror no longer matches the
// native queue — re-read the truth.
@@ -481,6 +482,20 @@ export async function skipToNext(): Promise<void> {
export async function skipToPrevious(): Promise<void> {
await ensurePlayerReady();
// Use RNTP's position so headless Bluetooth/Auto commands do not depend on
// the UI-mounted progress mirror. A failed read preserves the old skip path.
let nativePosition: number | null = null;
try {
nativePosition = (await TrackPlayer.getProgress()).position;
} catch {
// Fall through to the existing previous-track behavior.
}
if (nativePosition != null && shouldRestartOnPrevious(nativePosition)) {
await seekTo(0);
return;
}
const [nativeQueue, nativeIndex] = await Promise.all([
TrackPlayer.getQueue(),
TrackPlayer.getActiveTrackIndex(),
+18
View File
@@ -0,0 +1,18 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import {
PREVIOUS_RESTART_THRESHOLD_SECONDS,
shouldRestartOnPrevious,
} from './playbackNavigation.ts';
test('restarts only after crossing the three-second threshold', () => {
assert.equal(shouldRestartOnPrevious(3.001), true);
assert.equal(shouldRestartOnPrevious(PREVIOUS_RESTART_THRESHOLD_SECONDS), false);
assert.equal(shouldRestartOnPrevious(0), false);
});
test('invalid and negative positions retain previous-track behavior', () => {
assert.equal(shouldRestartOnPrevious(-1), false);
assert.equal(shouldRestartOnPrevious(Number.NaN), false);
assert.equal(shouldRestartOnPrevious(Number.POSITIVE_INFINITY), false);
});
+9
View File
@@ -0,0 +1,9 @@
export const PREVIOUS_RESTART_THRESHOLD_SECONDS = 3;
/** Match desktop Astra: restart only after crossing the previous-track cutoff. */
export function shouldRestartOnPrevious(positionSeconds: number): boolean {
return (
Number.isFinite(positionSeconds) &&
positionSeconds > PREVIOUS_RESTART_THRESHOLD_SECONDS
);
}