fix(player): stabilize seek interaction and remove misleading secondary bar refs #75

cx
This commit is contained in:
vicrodh committed 2026-02-16 22:48:39 -06:00
1 parent 39bbbdc230
commit 0c66a14249
3 files changed
+70 -16

No files matched your search

+6 -7
View File
@@ -4130,16 +4130,15 @@ pub async fn v2_seek(
runtime.manager().check_requirements(CommandRequirement::RequiresClientInit).await?; runtime.manager().check_requirements(CommandRequirement::RequiresClientInit).await?;
log::info!("[V2] Command: seek {}", position); log::info!("[V2] Command: seek {}", position);
let bridge_guard = bridge.get().await; let bridge_guard = bridge.get().await;
let result = bridge_guard.seek(position).map_err(RuntimeError::Internal); bridge_guard.seek(position).map_err(RuntimeError::Internal)?;
// Update MPRIS with new position // Update MPRIS with effective playback state only after successful seek.
let playback_state = bridge_guard.get_playback_state(); let playback_state = bridge_guard.get_playback_state();
app_state.media_controls.set_playback_with_progress( app_state
playback_state.is_playing, .media_controls
position, .set_playback_with_progress(playback_state.is_playing, playback_state.position);
);
result Ok(())
} }
/// Set volume (0.0 - 1.0) (V2) /// Set volume (0.0 - 1.0) (V2)
+12 -6
View File
@@ -125,6 +125,7 @@
let isDraggingProgress = $state(false); let isDraggingProgress = $state(false);
let isDraggingVolume = $state(false); let isDraggingVolume = $state(false);
let showArtworkPreview = $state(false); let showArtworkPreview = $state(false);
let dragPreviewTime = $state<number | null>(null);
// Offline state // Offline state
let isOffline = $state(checkIsOffline()); let isOffline = $state(checkIsOffline());
@@ -152,9 +153,10 @@
} }
} }
const progress = $derived(duration > 0 ? (currentTime / duration) * 100 : 0); const effectiveTime = $derived(dragPreviewTime ?? currentTime);
const progress = $derived(duration > 0 ? (effectiveTime / duration) * 100 : 0);
const hasTrack = $derived(trackTitle !== ''); const hasTrack = $derived(trackTitle !== '');
const remainingTime = $derived(Math.max(0, duration - currentTime)); const remainingTime = $derived(Math.max(0, duration - effectiveTime));
function formatTime(seconds: number): string { function formatTime(seconds: number): string {
const mins = Math.floor(seconds / 60); const mins = Math.floor(seconds / 60);
@@ -172,7 +174,7 @@
const rect = progressRef.getBoundingClientRect(); const rect = progressRef.getBoundingClientRect();
const percentage = Math.max(0, Math.min(100, ((e.clientX - rect.left) / rect.width) * 100)); const percentage = Math.max(0, Math.min(100, ((e.clientX - rect.left) / rect.width) * 100));
const newTime = Math.round((percentage / 100) * duration); const newTime = Math.round((percentage / 100) * duration);
onSeek?.(newTime); dragPreviewTime = newTime;
} }
} }
@@ -195,8 +197,12 @@
} }
function handleMouseUp() { function handleMouseUp() {
if (isDraggingProgress && dragPreviewTime !== null) {
onSeek?.(dragPreviewTime);
}
isDraggingProgress = false; isDraggingProgress = false;
isDraggingVolume = false; isDraggingVolume = false;
dragPreviewTime = null;
} }
$effect(() => { $effect(() => {
@@ -529,14 +535,14 @@
width: 100%; width: 100%;
height: 3px; height: 3px;
background: var(--border-subtle); background: var(--border-subtle);
border-radius: 2px; border-radius: 999px;
overflow: hidden; overflow: hidden;
} }
.seekbar-fill { .seekbar-fill {
height: 100%; height: 100%;
background: var(--accent-primary, #6366f1); background: var(--accent-primary, #6366f1);
border-radius: 2px; border-radius: 999px;
transition: width 100ms linear; transition: width 100ms linear;
} }
@@ -558,7 +564,7 @@
} }
.seekbar:hover .seekbar-track { .seekbar:hover .seekbar-track {
height: 4px; /* keep both layers stable on hover */
} }
/* ===== Controls Row ===== */ /* ===== Controls Row ===== */
+52 -3
View File
@@ -143,6 +143,12 @@ let isAdvancingTrack = false;
let isSkipping = false; let isSkipping = false;
let queueEnded = false; let queueEnded = false;
let normalizationGain: number | null = null; // Current normalization gain (null = not active) let normalizationGain: number | null = null; // Current normalization gain (null = not active)
let pendingSeekPosition: number | null = null;
let seekRequestInFlight = false;
let seekTargetPosition: number | null = null;
let seekGuardUntilMs = 0;
const SEEK_GUARD_WINDOW_MS = 1500;
const SEEK_SETTLE_TOLERANCE_SECS = 1;
// Callbacks for track advancement (set by consumer) // Callbacks for track advancement (set by consumer)
let onTrackEnded: (() => Promise<void>) | null = null; let onTrackEnded: (() => Promise<void>) | null = null;
@@ -210,6 +216,28 @@ export function getNormalizationGain(): number | null {
return normalizationGain; return normalizationGain;
} }
async function flushPendingSeek(): Promise<void> {
if (seekRequestInFlight) return;
if (pendingSeekPosition === null) return;
const targetPosition = pendingSeekPosition;
pendingSeekPosition = null;
seekTargetPosition = targetPosition;
seekGuardUntilMs = Date.now() + SEEK_GUARD_WINDOW_MS;
seekRequestInFlight = true;
try {
await invoke('v2_seek', { position: Math.floor(targetPosition) });
} catch (err) {
console.error('Failed to seek:', err);
} finally {
seekRequestInFlight = false;
if (pendingSeekPosition !== null) {
void flushPendingSeek();
}
}
}
// ============ State Setter ============ // ============ State Setter ============
export interface PlayerState { export interface PlayerState {
@@ -418,8 +446,8 @@ export async function seek(position: number): Promise<void> {
await castSeek(Math.floor(clampedPosition)); await castSeek(Math.floor(clampedPosition));
return; return;
} }
pendingSeekPosition = clampedPosition;
await invoke('v2_seek', { position: Math.floor(clampedPosition) }); void flushPendingSeek();
} catch (err) { } catch (err) {
console.error('Failed to seek:', err); console.error('Failed to seek:', err);
} }
@@ -655,7 +683,24 @@ async function handlePlaybackEvent(event: PlaybackEvent): Promise<void> {
// Update playback state if track matches // Update playback state if track matches
if (event.track_id === currentTrack.id) { if (event.track_id === currentTrack.id) {
currentTime = event.position; const now = Date.now();
const seekGuardActive = seekTargetPosition !== null && now < seekGuardUntilMs;
if (seekGuardActive) {
const delta = Math.abs(event.position - seekTargetPosition);
if (delta <= SEEK_SETTLE_TOLERANCE_SECS) {
seekTargetPosition = null;
seekGuardUntilMs = 0;
currentTime = event.position;
} else {
// Ignore stale position updates briefly after seek to avoid UI snap-back.
}
} else {
if (seekTargetPosition !== null && now >= seekGuardUntilMs) {
seekTargetPosition = null;
seekGuardUntilMs = 0;
}
currentTime = event.position;
}
isPlaying = event.is_playing; isPlaying = event.is_playing;
// Update volume from backend (e.g., changed via remote control or system) // Update volume from backend (e.g., changed via remote control or system)
@@ -802,6 +847,10 @@ export function isPollingActive(): boolean {
* Reset all state (for logout) * Reset all state (for logout)
*/ */
export function reset(): void { export function reset(): void {
pendingSeekPosition = null;
seekRequestInFlight = false;
seekTargetPosition = null;
seekGuardUntilMs = 0;
stopPolling(); stopPolling();
currentTrack = null; currentTrack = null;
isPlaying = false; isPlaying = false;