File tree Expand file tree Collapse file tree 1 file changed +21
-3
lines changed
Expand file tree Collapse file tree 1 file changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -64,11 +64,29 @@ func (s *State) reset() {
6464}
6565
6666func (s * State ) trackPosition () int64 {
67- if s .player .IsPaused {
67+ // If paused or not actually playing, use raw position value
68+ if s .player .IsPaused || ! s .player .IsPlaying {
69+ return s .player .PositionAsOfTimestamp
70+ }
71+
72+ // Calculate dynamic position only if playback is actually active
73+ now := time .Now ().UnixMilli ()
74+ elapsed := now - s .player .Timestamp
75+
76+ // Validate timestamp freshness: if elapsed time exceeds 10 minutes (600000ms),
77+ // timestamp is likely stale (e.g., from a previous session), use raw position
78+ const maxReasonableElapsed = 10 * 60 * 1000 // 10 minutes in milliseconds
79+ if elapsed > maxReasonableElapsed || elapsed < 0 {
6880 return s .player .PositionAsOfTimestamp
69- } else {
70- return time .Now ().UnixMilli () - s .player .Timestamp + s .player .PositionAsOfTimestamp
7181 }
82+
83+ calculated := s .player .PositionAsOfTimestamp + elapsed
84+ // Ensure position is non-negative (shouldn't happen, but defensive)
85+ if calculated < 0 {
86+ return s .player .PositionAsOfTimestamp
87+ }
88+
89+ return calculated
7290}
7391
7492// Update timestamp, and updating the player position timestamp according to how
You can’t perform that action at this time.
0 commit comments