mirror of
https://github.com/rommapp/romm.git
synced 2026-12-05 05:07:31 +01:00
feat(v2): smooth, scrubber-style track progress
- usePlaybackTime advances the playing position every frame from the audio's coarse time reports, so the progress bar and the pill's ring move continuously instead of in steps. - SeekBar is the shared timeline for the soundtrack panel and the mini player card: elapsed time, a scrubber and the duration. While dragging it follows the finger rather than the playback clock, and only it re-renders per frame, not the whole panel or card. - RSlider gains a `scrubber` look (with a story): a thin track with no thumb at rest that thickens and shows a solid thumb on hover, keyboard focus or drag, which sets the progress bar apart from volume. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01S76JZm1jjh32KhBbPCBvGW
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
// The mini player's body in the soundtrack header's look. Floats in a corner on
|
||||
// desktop and opens as a sheet from the top bar on phones.
|
||||
import { RBtn, RSlider, RSpinner } from "@v2/lib";
|
||||
import { RBtn, RSpinner } from "@v2/lib";
|
||||
import { storeToRefs } from "pinia";
|
||||
import { computed } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
@@ -10,9 +10,9 @@ import { ROUTES } from "@/plugins/router";
|
||||
import useSoundtrackPlayer from "@/stores/soundtrackPlayer";
|
||||
import AmbientArt from "@/v2/components/Soundtrack/AmbientArt.vue";
|
||||
import NowPlayingChips from "@/v2/components/Soundtrack/NowPlayingChips.vue";
|
||||
import SeekBar from "@/v2/components/Soundtrack/SeekBar.vue";
|
||||
import VolumeControl from "@/v2/components/Soundtrack/VolumeControl.vue";
|
||||
import { nowPlayingCaption, playerCoverUrl } from "@/v2/utils/soundtrackTracks";
|
||||
import { formatTrackTime } from "@/v2/utils/time";
|
||||
|
||||
defineOptions({ inheritAttrs: false });
|
||||
|
||||
@@ -25,8 +25,6 @@ const {
|
||||
playlist,
|
||||
isPlaying,
|
||||
isBuffering,
|
||||
currentTime,
|
||||
duration,
|
||||
hasPrevious,
|
||||
hasNext,
|
||||
isShuffled,
|
||||
@@ -45,13 +43,6 @@ const position = computed(() => {
|
||||
);
|
||||
});
|
||||
|
||||
function seekValueText(v: number): string {
|
||||
return t("rom.seek-progress", {
|
||||
current: formatTrackTime(v),
|
||||
duration: formatTrackTime(duration.value),
|
||||
});
|
||||
}
|
||||
|
||||
function openRom() {
|
||||
if (!track.value) return;
|
||||
// Straight to the Soundtrack subtab, where the full player takes over.
|
||||
@@ -160,22 +151,7 @@ function openRom() {
|
||||
<VolumeControl size="small" />
|
||||
</div>
|
||||
|
||||
<div class="r-v2-np-card__seek">
|
||||
<span class="r-v2-np-card__time">{{ formatTrackTime(currentTime) }}</span>
|
||||
<RSlider
|
||||
:model-value="currentTime"
|
||||
:max="duration || 0"
|
||||
:step="0.1"
|
||||
color="primary"
|
||||
class="r-v2-np-card__slider"
|
||||
:aria-label="t('rom.soundtrack-seek')"
|
||||
:aria-valuetext="seekValueText(currentTime)"
|
||||
@update:model-value="(v: number) => store.seek(v)"
|
||||
/>
|
||||
<span class="r-v2-np-card__time r-v2-np-card__time--right">
|
||||
{{ formatTrackTime(duration) }}
|
||||
</span>
|
||||
</div>
|
||||
<SeekBar />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -266,25 +242,4 @@ function openRom() {
|
||||
.r-v2-np-card__play {
|
||||
border-radius: var(--r-radius-full);
|
||||
}
|
||||
|
||||
.r-v2-np-card__seek {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--r-space-2);
|
||||
}
|
||||
|
||||
.r-v2-np-card__slider {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.r-v2-np-card__time {
|
||||
min-width: 36px;
|
||||
color: var(--r-color-fg-muted);
|
||||
font-size: var(--r-font-size-xs);
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
.r-v2-np-card__time--right {
|
||||
text-align: right;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -8,26 +8,21 @@ import { useI18n } from "vue-i18n";
|
||||
import useSoundtrackPlayer from "@/stores/soundtrackPlayer";
|
||||
import NowPlayingCard from "@/v2/components/Soundtrack/NowPlayingCard.vue";
|
||||
import { useMiniPlayerVisible } from "@/v2/composables/useMiniPlayerVisible";
|
||||
import { usePlaybackTime } from "@/v2/composables/usePlaybackTime";
|
||||
import { playerCoverUrl } from "@/v2/utils/soundtrackTracks";
|
||||
|
||||
defineOptions({ inheritAttrs: false });
|
||||
|
||||
const { t } = useI18n();
|
||||
const store = useSoundtrackPlayer();
|
||||
const {
|
||||
meta,
|
||||
isPlaying,
|
||||
isBuffering,
|
||||
currentTime,
|
||||
duration,
|
||||
hasPrevious,
|
||||
hasNext,
|
||||
} = storeToRefs(store);
|
||||
const { meta, isPlaying, isBuffering, duration, hasPrevious, hasNext } =
|
||||
storeToRefs(store);
|
||||
const visible = useMiniPlayerVisible();
|
||||
const playbackTime = usePlaybackTime();
|
||||
|
||||
const coverUrl = computed(() => playerCoverUrl(meta.value));
|
||||
const progress = computed(() =>
|
||||
duration.value > 0 ? (currentTime.value / duration.value) * 100 : 0,
|
||||
duration.value > 0 ? (playbackTime.value / duration.value) * 100 : 0,
|
||||
);
|
||||
</script>
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ import {
|
||||
RBtn,
|
||||
RIcon,
|
||||
RSkeletonBlock,
|
||||
RSlider,
|
||||
RSpinner,
|
||||
RVirtualScroller,
|
||||
} from "@v2/lib";
|
||||
@@ -20,6 +19,7 @@ import useSoundtrackPlayer, {
|
||||
} from "@/stores/soundtrackPlayer";
|
||||
import AmbientArt from "@/v2/components/Soundtrack/AmbientArt.vue";
|
||||
import NowPlayingChips from "@/v2/components/Soundtrack/NowPlayingChips.vue";
|
||||
import SeekBar from "@/v2/components/Soundtrack/SeekBar.vue";
|
||||
import EmptyState from "@/v2/components/shared/EmptyState.vue";
|
||||
import { useBreakpoint } from "@/v2/composables/useBreakpoint";
|
||||
import { useCan } from "@/v2/composables/useCan";
|
||||
@@ -94,8 +94,6 @@ const {
|
||||
track: activeStoreTrack,
|
||||
isPlaying,
|
||||
isBuffering,
|
||||
currentTime,
|
||||
duration,
|
||||
playlist,
|
||||
hasPrevious,
|
||||
hasNext,
|
||||
@@ -318,13 +316,6 @@ function downloadTrack(track: PanelTrack) {
|
||||
a.click();
|
||||
a.remove();
|
||||
}
|
||||
|
||||
function seekValueText(v: number): string {
|
||||
return t("rom.seek-progress", {
|
||||
current: formatTrackTime(v),
|
||||
duration: formatTrackTime(duration.value),
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -444,25 +435,7 @@ function seekValueText(v: number): string {
|
||||
/>
|
||||
<VolumeControl size="small" />
|
||||
</div>
|
||||
<div class="r-v2-stp__timeline">
|
||||
<span class="r-v2-stp__time">{{
|
||||
formatTrackTime(currentTime)
|
||||
}}</span>
|
||||
<RSlider
|
||||
:model-value="currentTime"
|
||||
:max="duration || 0"
|
||||
:step="0.1"
|
||||
:disabled="!activeTrack"
|
||||
color="primary"
|
||||
class="r-v2-stp__slider"
|
||||
:aria-label="t('rom.soundtrack-seek')"
|
||||
:aria-valuetext="seekValueText(currentTime)"
|
||||
@update:model-value="(v: number) => player.seek(v)"
|
||||
/>
|
||||
<span class="r-v2-stp__time r-v2-stp__time--right">
|
||||
{{ formatTrackTime(duration) }}
|
||||
</span>
|
||||
</div>
|
||||
<SeekBar :disabled="!activeTrack" class="r-v2-stp__timeline" />
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
@@ -745,25 +718,6 @@ function seekValueText(v: number): string {
|
||||
|
||||
.r-v2-stp__timeline {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--r-space-2);
|
||||
}
|
||||
|
||||
.r-v2-stp__slider {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.r-v2-stp__time {
|
||||
font-variant-numeric: tabular-nums;
|
||||
color: var(--r-color-fg-muted);
|
||||
font-size: var(--r-font-size-xs);
|
||||
min-width: 40px;
|
||||
}
|
||||
|
||||
.r-v2-stp__time--right {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
/* Queue */
|
||||
|
||||
83
frontend/src/v2/components/Soundtrack/SeekBar.vue
Normal file
83
frontend/src/v2/components/Soundtrack/SeekBar.vue
Normal file
@@ -0,0 +1,83 @@
|
||||
<script setup lang="ts">
|
||||
// The track timeline shared by the soundtrack panel and the mini player: the
|
||||
// elapsed and total time around a scrubber that advances smoothly.
|
||||
import { RSlider } from "@v2/lib";
|
||||
import { storeToRefs } from "pinia";
|
||||
import { computed, ref } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import useSoundtrackPlayer from "@/stores/soundtrackPlayer";
|
||||
import { usePlaybackTime } from "@/v2/composables/usePlaybackTime";
|
||||
import { formatTrackTime } from "@/v2/utils/time";
|
||||
|
||||
defineOptions({ inheritAttrs: false });
|
||||
|
||||
defineProps<{ disabled?: boolean }>();
|
||||
|
||||
const { t } = useI18n();
|
||||
const store = useSoundtrackPlayer();
|
||||
const { duration } = storeToRefs(store);
|
||||
const playbackTime = usePlaybackTime();
|
||||
|
||||
// While dragging, the thumb follows the finger instead of the playback clock.
|
||||
const dragTime = ref<number | null>(null);
|
||||
const shownTime = computed(() => dragTime.value ?? playbackTime.value);
|
||||
|
||||
const valueText = computed(() =>
|
||||
t("rom.seek-progress", {
|
||||
current: formatTrackTime(shownTime.value),
|
||||
duration: formatTrackTime(duration.value),
|
||||
}),
|
||||
);
|
||||
|
||||
function onSeek(value: number) {
|
||||
if (dragTime.value !== null) dragTime.value = value;
|
||||
store.seek(value);
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="r-v2-seek" v-bind="$attrs">
|
||||
<span class="r-v2-seek__time">{{ formatTrackTime(shownTime) }}</span>
|
||||
<RSlider
|
||||
:model-value="shownTime"
|
||||
:max="duration || 0"
|
||||
:step="0.1"
|
||||
:disabled="disabled"
|
||||
color="primary"
|
||||
scrubber
|
||||
class="r-v2-seek__slider"
|
||||
:aria-label="t('rom.soundtrack-seek')"
|
||||
:aria-valuetext="valueText"
|
||||
@start="(value: number) => (dragTime = value)"
|
||||
@end="dragTime = null"
|
||||
@update:model-value="onSeek"
|
||||
/>
|
||||
<span class="r-v2-seek__time r-v2-seek__time--right">
|
||||
{{ formatTrackTime(duration) }}
|
||||
</span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.r-v2-seek {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--r-space-2);
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.r-v2-seek__slider {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.r-v2-seek__time {
|
||||
min-width: 36px;
|
||||
color: var(--r-color-fg-muted);
|
||||
font-size: var(--r-font-size-xs);
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
.r-v2-seek__time--right {
|
||||
text-align: right;
|
||||
}
|
||||
</style>
|
||||
50
frontend/src/v2/composables/usePlaybackTime/index.ts
Normal file
50
frontend/src/v2/composables/usePlaybackTime/index.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
// usePlaybackTime — the playing track's position, advanced every frame from
|
||||
// the audio's coarse time reports so progress UI moves continuously.
|
||||
import { storeToRefs } from "pinia";
|
||||
import { onScopeDispose, ref, watch, type Ref } from "vue";
|
||||
import useSoundtrackPlayer from "@/stores/soundtrackPlayer";
|
||||
|
||||
export function usePlaybackTime(): Ref<number> {
|
||||
const { currentTime, duration, isPlaying, isBuffering } = storeToRefs(
|
||||
useSoundtrackPlayer(),
|
||||
);
|
||||
|
||||
const time = ref(currentTime.value);
|
||||
let anchorTime = currentTime.value;
|
||||
let anchorStamp = performance.now();
|
||||
let frame = 0;
|
||||
|
||||
function tick(now: number) {
|
||||
const elapsed = (now - anchorStamp) / 1000;
|
||||
const end = duration.value || Number.POSITIVE_INFINITY;
|
||||
time.value = Math.min(end, anchorTime + elapsed);
|
||||
frame = requestAnimationFrame(tick);
|
||||
}
|
||||
|
||||
function stop() {
|
||||
cancelAnimationFrame(frame);
|
||||
frame = 0;
|
||||
}
|
||||
|
||||
watch(currentTime, (reported) => {
|
||||
anchorTime = reported;
|
||||
anchorStamp = performance.now();
|
||||
time.value = reported;
|
||||
});
|
||||
|
||||
watch(
|
||||
[isPlaying, isBuffering],
|
||||
([playing, buffering]) => {
|
||||
stop();
|
||||
if (!playing || buffering) return;
|
||||
anchorTime = time.value;
|
||||
anchorStamp = performance.now();
|
||||
frame = requestAnimationFrame(tick);
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
onScopeDispose(stop);
|
||||
|
||||
return time;
|
||||
}
|
||||
@@ -126,6 +126,10 @@ export const ColorLadder: Story = {
|
||||
|
||||
// ── States ─────────────────────────────────────────────────────────
|
||||
|
||||
export const Scrubber: Story = {
|
||||
args: { modelValue: 35, scrubber: true },
|
||||
};
|
||||
|
||||
export const Vertical: Story = {
|
||||
args: { modelValue: 60, vertical: true },
|
||||
render: (args) => ({
|
||||
|
||||
@@ -33,6 +33,9 @@ interface Props {
|
||||
/** Stand the track upright, filling the slider's height (set one on it).
|
||||
* Meant for a bare track: pair with `valuePosition="none"`. */
|
||||
vertical?: boolean;
|
||||
/** Media scrubber look: a thin track with no thumb at rest, thickening
|
||||
* with a solid thumb on hover, keyboard focus or drag. */
|
||||
scrubber?: boolean;
|
||||
/** ARIA label when no visible label exists. */
|
||||
ariaLabel?: string;
|
||||
}
|
||||
@@ -49,6 +52,7 @@ const props = withDefaults(defineProps<Props>(), {
|
||||
valueSuffix: "",
|
||||
showTicks: false,
|
||||
vertical: false,
|
||||
scrubber: false,
|
||||
ariaLabel: undefined,
|
||||
});
|
||||
|
||||
@@ -174,6 +178,7 @@ function onVerticalPointerMove(evt: PointerEvent) {
|
||||
'r-slider--readonly': readonly,
|
||||
'r-slider--dragging': dragging,
|
||||
'r-slider--vertical': vertical,
|
||||
'r-slider--scrubber': scrubber,
|
||||
},
|
||||
]"
|
||||
:style="{
|
||||
@@ -421,6 +426,58 @@ function onVerticalPointerMove(evt: PointerEvent) {
|
||||
background: color-mix(in srgb, var(--r-slider-accent), white 14%);
|
||||
}
|
||||
|
||||
/* Scrubber: the track and thumb read their size from variables that the
|
||||
hover, focus and drag states raise. */
|
||||
.r-slider--scrubber {
|
||||
--r-scrub-track-h: 3px;
|
||||
--r-scrub-thumb-opacity: 0;
|
||||
}
|
||||
html[data-input="mouse"] .r-slider--scrubber:not(.r-slider--disabled):hover,
|
||||
html[data-input="key"] .r-slider--scrubber:focus-within,
|
||||
html[data-input="pad"] .r-slider--scrubber:focus-within,
|
||||
.r-slider--scrubber.r-slider--dragging {
|
||||
--r-scrub-track-h: 6px;
|
||||
--r-scrub-thumb-opacity: 1;
|
||||
}
|
||||
.r-slider--scrubber .r-slider__native::-webkit-slider-runnable-track {
|
||||
height: var(--r-scrub-track-h);
|
||||
border: 0;
|
||||
transition: height var(--r-motion-fast) var(--r-motion-ease-out);
|
||||
}
|
||||
.r-slider--scrubber .r-slider__native::-webkit-slider-thumb {
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
margin-top: calc(var(--r-scrub-track-h) / 2 - 6px);
|
||||
border: 0;
|
||||
opacity: var(--r-scrub-thumb-opacity);
|
||||
transition: opacity var(--r-motion-fast) var(--r-motion-ease-out);
|
||||
}
|
||||
.r-slider.r-slider--scrubber:not(.r-slider--disabled):not(.r-slider--readonly)
|
||||
.r-slider__native::-webkit-slider-runnable-track {
|
||||
box-shadow: none;
|
||||
}
|
||||
.r-slider.r-slider--scrubber:not(.r-slider--disabled):not(.r-slider--readonly)
|
||||
.r-slider__native::-webkit-slider-thumb {
|
||||
transform: none;
|
||||
box-shadow: var(--r-elev-1);
|
||||
}
|
||||
.r-slider--scrubber .r-slider__native::-moz-range-track,
|
||||
.r-slider--scrubber .r-slider__native::-moz-range-progress {
|
||||
height: var(--r-scrub-track-h);
|
||||
border: 0;
|
||||
}
|
||||
.r-slider--scrubber .r-slider__native::-moz-range-thumb {
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
border: 0;
|
||||
opacity: var(--r-scrub-thumb-opacity);
|
||||
}
|
||||
.r-slider.r-slider--scrubber:not(.r-slider--disabled):not(.r-slider--readonly)
|
||||
.r-slider__native::-moz-range-thumb {
|
||||
transform: none;
|
||||
box-shadow: var(--r-elev-1);
|
||||
}
|
||||
|
||||
/* Modality-gated keyboard focus ring. */
|
||||
html[data-input="key"] .r-slider__native:focus::-webkit-slider-thumb,
|
||||
html[data-input="pad"] .r-slider__native:focus::-webkit-slider-thumb {
|
||||
|
||||
Reference in New Issue
Block a user