refactor: homologate seek to preview+commit in ImmersivePlayer and Miniplayer
Replace immediate seek-on-drag with the NowPlayingBar pattern: preview the position visually during drag, commit the seek only on mouseup. Both PlayerControlsCompact and MiniPlayerFooter now use dragPreviewTime/effectiveTime, matching NowPlayingBar behavior.
This commit is contained in:
2 files changed
+18
-6
No files matched your search
@@ -81,8 +81,10 @@
|
||||
let volumeRef: HTMLDivElement | null = $state(null);
|
||||
let isDraggingProgress = $state(false);
|
||||
let isDraggingVolume = $state(false);
|
||||
let dragPreviewTime = $state<number | null>(null);
|
||||
|
||||
const progress = $derived((currentTime / duration) * 100 || 0);
|
||||
const effectiveTime = $derived(dragPreviewTime ?? currentTime);
|
||||
const progress = $derived((effectiveTime / duration) * 100 || 0);
|
||||
|
||||
function formatTime(seconds: number): string {
|
||||
if (!seconds || !isFinite(seconds)) return '0:00';
|
||||
@@ -100,7 +102,7 @@
|
||||
if (progressRef) {
|
||||
const rect = progressRef.getBoundingClientRect();
|
||||
const percentage = Math.max(0, Math.min(100, ((e.clientX - rect.left) / rect.width) * 100));
|
||||
onSeek(Math.round((percentage / 100) * duration));
|
||||
dragPreviewTime = Math.round((percentage / 100) * duration);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,8 +126,12 @@
|
||||
}
|
||||
|
||||
function handleMouseUp() {
|
||||
if (isDraggingProgress && dragPreviewTime !== null) {
|
||||
onSeek(dragPreviewTime);
|
||||
}
|
||||
isDraggingProgress = false;
|
||||
isDraggingVolume = false;
|
||||
dragPreviewTime = null;
|
||||
}
|
||||
|
||||
$effect(() => {
|
||||
@@ -228,7 +234,7 @@
|
||||
|
||||
<!-- Center: Time + Playback + Time -->
|
||||
<div class="playback-group">
|
||||
<span class="time-text">{formatTime(currentTime)}</span>
|
||||
<span class="time-text">{formatTime(effectiveTime)}</span>
|
||||
|
||||
<button
|
||||
class="control-btn nav"
|
||||
|
||||
@@ -71,9 +71,11 @@
|
||||
let isDraggingSeek = $state(false);
|
||||
let isDraggingVolume = $state(false);
|
||||
let volumePopoverOpen = $state(false);
|
||||
let dragPreviewTime = $state<number | null>(null);
|
||||
let microTrackOverflow = $state(0);
|
||||
|
||||
const progress = $derived(duration > 0 ? Math.max(0, Math.min(100, (currentTime / duration) * 100)) : 0);
|
||||
const effectiveTime = $derived(dragPreviewTime ?? currentTime);
|
||||
const progress = $derived(duration > 0 ? Math.max(0, Math.min(100, (effectiveTime / duration) * 100)) : 0);
|
||||
const tickerSpeed = 40;
|
||||
const microTrackOffset = $derived(microTrackOverflow > 0 ? `-${microTrackOverflow + 16}px` : '0px');
|
||||
const microTrackDuration = $derived(microTrackOverflow > 0 ? `${(microTrackOverflow + 16) / tickerSpeed}s` : '0s');
|
||||
@@ -108,7 +110,7 @@
|
||||
if (!targetRef || duration <= 0) return;
|
||||
const rect = targetRef.getBoundingClientRect();
|
||||
const percentage = Math.max(0, Math.min(100, ((event.clientX - rect.left) / rect.width) * 100));
|
||||
onSeek(Math.round((percentage / 100) * duration));
|
||||
dragPreviewTime = Math.round((percentage / 100) * duration);
|
||||
}
|
||||
|
||||
function updateVolume(event: MouseEvent): void {
|
||||
@@ -139,8 +141,12 @@
|
||||
}
|
||||
|
||||
function handleMouseUp(): void {
|
||||
if (isDraggingSeek && dragPreviewTime !== null) {
|
||||
onSeek(dragPreviewTime);
|
||||
}
|
||||
isDraggingSeek = false;
|
||||
isDraggingVolume = false;
|
||||
dragPreviewTime = null;
|
||||
}
|
||||
|
||||
$effect(() => {
|
||||
@@ -225,7 +231,7 @@
|
||||
</div>
|
||||
|
||||
<div class="times">
|
||||
<span>{formatTime(currentTime)}</span>
|
||||
<span>{formatTime(effectiveTime)}</span>
|
||||
<span>{formatTime(duration)}</span>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
Reference in new issue
Block a user