Skip to content

Commit b0fef94

Browse files
committed
improve seek detection
account for elapsed time and play/pause state. also rename to SeekChanged
1 parent 7dba9dd commit b0fef94

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

connect/src/spirc.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,6 @@ pub struct QueueUpdateEvent {
152152
pub enum PlayerUpdateReason {
153153
/// Track changed
154154
TrackChanged,
155-
/// Position changed
156-
PositionChanged,
157155
/// Play/pause state changed
158156
PlayPauseChanged,
159157
/// Shuffle mode changed
@@ -162,6 +160,8 @@ pub enum PlayerUpdateReason {
162160
RepeatChanged,
163161
/// Context changed
164162
ContextChanged,
163+
/// Seek detected
164+
SeekChanged,
165165
/// Other state change
166166
Other,
167167
}
@@ -1244,11 +1244,18 @@ impl SpircTask {
12441244
}
12451245

12461246
// Detect seek: position jump (not just natural progress)
1247-
let position_diff =
1248-
(state.position_as_of_timestamp - last.position_as_of_timestamp).abs();
1249-
if position_diff > 5000 {
1250-
// threshold: 5 seconds
1251-
PlayerUpdateReason::PositionChanged
1247+
let time_diff = state.timestamp.saturating_sub(last.timestamp);
1248+
let expected_position = if state.is_playing {
1249+
// Account for natural progression if playing
1250+
last.position_as_of_timestamp + time_diff
1251+
} else {
1252+
// If paused, position shouldn't change
1253+
last.position_as_of_timestamp
1254+
};
1255+
1256+
let position_delta = (state.position_as_of_timestamp as i64 - expected_position as i64).abs();
1257+
if position_delta > 5000 {
1258+
PlayerUpdateReason::SeekChanged
12521259
} else {
12531260
// No significant change detected
12541261
PlayerUpdateReason::Other

0 commit comments

Comments
 (0)