mirror of
https://github.com/Boof2015/astra-mobile.git
synced 2026-08-12 05:10:52 +02:00
fix prev restart threshold
This commit is contained in:
@@ -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(),
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
@@ -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
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user