fix(27): do full reset sequence when playing from beginning

Native client needs Stop -> Seek(0) -> Play sequence to reliably
start playback after track has finished. Previously we only did
this when "atEnd", but after track finishes and resets to 0, the
"atEnd" check is false.

Fix: Also do the full reset sequence when position is at the
beginning (< 100ms). This ensures native client is in the right
state whether starting fresh or restarting after track finished.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Nuwan 2026-03-02 13:39:15 +05:30
parent fe589f4ac2
commit 79ddf613f9
1 changed files with 7 additions and 6 deletions

View File

@ -299,15 +299,16 @@ const JKSessionBackingTrackPlayer = ({
// Check if we're at the very end (within 50ms to avoid false positives from slider dragging)
const atEnd = currentPositionMs >= durationMs - 50 && durationMs > 0;
console.log('[PLAY] At end check:', { currentPositionMs, durationMs, atEnd, threshold: durationMs - 50 });
// Check if we're at the beginning (position 0 or very close)
const atBeginning = currentPositionMs < 100;
console.log('[PLAY] Position check:', { currentPositionMs, durationMs, atEnd, atBeginning });
if (atEnd) {
console.log('[PLAY] At end, resetting to start');
// Stop first to reset state
if (atEnd || atBeginning) {
// Native client needs Stop -> Seek -> Play sequence to reliably start
// This handles both "at end" and "at beginning after track finished" cases
console.log('[PLAY] At end or beginning, doing full reset sequence');
await jamClient.SessionStopPlay();
// Seek to start
await jamClient.SessionTrackSeekMs(0);
// Update UI state
setCurrentPositionMs(0);
setCurrentTime('0:00');
}