feat(player): add timeline metadata and simplify controls
Continuous Integration / build_web (push) Failing after 1s
Continuous Integration / build (macos-latest) (push) Skipped
Continuous Integration / build (ubuntu-22.04) (push) Skipped
Continuous Integration / build (windows-11-arm) (push) Skipped
Continuous Integration / build (windows-latest) (push) Skipped
Continuous Integration / nightly_release (push) Skipped

Show chapter ticks, intro/recap/credits bands and a subtitle-derived dialogue density lane on the seek bar. Reduce the control bar to playback, volume, subtitles and fullscreen; move the remaining actions to settings or the top bar.
This commit is contained in:
1xDed committed 2026-12-04 00:34:20 +03:00
1 parent 3e9e8698bc
commit 8ba09f9cfd
4 files changed
+275 -195

No files matched your search

@@ -1,6 +1,10 @@
import type { TrickplayInfoDto } from "@jellyfin/sdk/lib/generated-client";
import type {
MediaSegmentDto,
TrickplayInfoDto,
} from "@jellyfin/sdk/lib/generated-client";
import { Slider, Tooltip, Typography } from "@mui/material";
import type { Instance } from "@popperjs/core";
import { useQuery } from "@tanstack/react-query";
import React, {
type MouseEvent,
useCallback,
@@ -14,6 +18,39 @@ import { ticksToMs } from "@/utils/date/time";
import { useApiInContext } from "@/utils/store/api";
import { usePlaybackStore } from "@/utils/store/playback";
const SEGMENT_LABELS: Record<string, string> = {
Intro: "Заставка",
Recap: "Ранее в серии",
Outro: "Титры",
Preview: "Следующая серия",
Commercial: "Реклама",
Unknown: "Сцена",
};
const parseDialogueBuckets = (vtt: string, durationTicks: number) => {
const buckets = 220;
const counts = new Array(buckets).fill(0);
const durationSec = durationTicks / 10_000_000;
if (!durationSec) return counts;
const cueStart = /(\d{1,2}):(\d{2}):(\d{2})[.,](\d{3})\s*-->/g;
for (const match of vtt.matchAll(cueStart)) {
const seconds =
Number(match[1]) * 3600 +
Number(match[2]) * 60 +
Number(match[3]) +
Number(match[4]) / 1000;
const index = Math.min(
buckets - 1,
Math.max(0, Math.floor((seconds / durationSec) * buckets)),
);
counts[index] += 1;
}
const max = Math.max(...counts, 1);
return counts.map((count) => count / max);
};
const ticksDisplay = (ticks: number) => {
const time = Math.round(ticks / 10000);
let formatedTime = "";
@@ -50,6 +87,7 @@ const BubbleSlider = () => {
mediaSource,
itemTrickplay,
itemId,
mediaSegments,
handleStartSeek,
handleStopSeek,
} = usePlaybackStore(
@@ -65,6 +103,7 @@ const BubbleSlider = () => {
mediaSource: state.mediaSource,
itemTrickplay: state.metadata.item.Trickplay,
itemId: state.metadata.item.Id,
mediaSegments: state.metadata.mediaSegments,
handleStartSeek: state.handleStartSeek,
handleStopSeek: state.handleStopSeek,
})),
@@ -121,13 +160,44 @@ const BubbleSlider = () => {
[itemDuration],
);
const chapterMarks = useMemo(() => {
const marks: { value: number }[] = [];
itemChapters?.forEach((val) => {
marks.push({ value: val.StartPositionTicks ?? 0 });
});
return marks;
}, [itemChapters]);
const dialogueTrack = useMemo(() => {
const tracks = mediaSource.subtitle?.allTracks ?? [];
return (
tracks.find(
(track) =>
track.Index === mediaSource.subtitle?.track &&
track.IsTextSubtitleStream,
) ?? tracks.find((track) => track.IsTextSubtitleStream)
);
}, [mediaSource.subtitle]);
const { data: dialogueBuckets } = useQuery({
queryKey: [
"video-dialogue-markers",
itemId,
mediaSource.id,
dialogueTrack?.Index,
itemDuration,
],
enabled: Boolean(
api && itemId && mediaSource.id && dialogueTrack && itemDuration,
),
staleTime: Number.POSITIVE_INFINITY,
retry: false,
queryFn: async () => {
if (!api || !itemId || !mediaSource.id || !dialogueTrack) return [];
const base = api.basePath.replace(/\/$/, "");
const response = await api.axiosInstance.get(
`${base}/Videos/${itemId}/${mediaSource.id}/Subtitles/${dialogueTrack.Index}/Stream.vtt`,
{ responseType: "text" },
);
const text =
typeof response.data === "string"
? response.data
: await response.data.text();
return parseDialogueBuckets(text, itemDuration ?? 0);
},
});
const sliderDisplayFormat = (value: number) => {
const currentChapter = itemChapters?.filter((chapter, index) => {
@@ -207,6 +277,14 @@ const BubbleSlider = () => {
}
const chapterName = currentChapter?.[0]?.Name;
const activeSegment: MediaSegmentDto | undefined =
mediaSegments?.Items?.find(
(segment) =>
value >= (segment.StartTicks ?? 0) && value < (segment.EndTicks ?? 0),
);
const segmentLabel = activeSegment?.Type
? SEGMENT_LABELS[activeSegment.Type]
: undefined;
return (
<div
@@ -229,6 +307,21 @@ const BubbleSlider = () => {
boxSizing: "border-box",
}}
>
{segmentLabel && (
<Typography
variant="caption"
sx={{
display: "block",
mb: 0.35,
color: "rgba(255,255,255,0.6)",
letterSpacing: "0.04em",
textTransform: "uppercase",
fontSize: "0.62rem",
}}
>
{segmentLabel}
</Typography>
)}
{chapterName && (
<Typography
variant="subtitle2"
@@ -272,16 +365,12 @@ const BubbleSlider = () => {
return (
<Tooltip
// title={sliderDisplayFormat(
// positionRef.current.x - areaRef.current!.getBoundingClientRect().x,
// )}
title={sliderDisplayFormat(hoverProgress)}
placement="top"
slotProps={{
popper: {
popperRef,
anchorEl: virtualAnchorEl,
// disablePortal: true,
},
tooltip: {
className: "glass",
@@ -295,52 +384,94 @@ const BubbleSlider = () => {
},
}}
>
<Slider
value={isUserSeeking ? seekValue : currentTime}
max={itemDuration ?? 0}
step={1}
onChange={(_, newValue) => {
// setIsUserSeeking(true);
Array.isArray(newValue)
? handleStartSeek(newValue[0])
: handleStartSeek(newValue);
}}
onChangeCommitted={(_, newValue) => {
// setIsUserSeeking(false);
// Array.isArray(newValue)
// ? setSeekValue(newValue[0])
// : setSeekValue(newValue);
if (Array.isArray(newValue)) {
handleStopSeek(newValue[0]);
} else {
handleStopSeek(newValue);
}
}}
sx={{
"& .MuiSlider-thumb": {
width: 14,
height: 14,
transition: "0.1s ease-in-out",
opacity: 0,
"&.Mui-active": {
width: 20,
height: 20,
<div className="video-player-timeline">
<div className="video-player-timeline-track" aria-hidden="true">
{mediaSegments?.Items?.map((segment) => {
const start = segment.StartTicks ?? 0;
const end = segment.EndTicks ?? start;
if (!itemDuration || end <= start) return null;
return (
<span
key={segment.Id ?? `${segment.Type}-${start}`}
className={`video-player-timeline-segment is-${(segment.Type ?? "unknown").toLowerCase()}`}
style={{
left: `${(start / itemDuration) * 100}%`,
width: `${((end - start) / itemDuration) * 100}%`,
}}
/>
);
})}
{dialogueBuckets?.map((density, index) =>
density > 0 ? (
<span
// biome-ignore lint/suspicious/noArrayIndexKey: fixed density buckets
key={`dialogue-${index}`}
className="video-player-timeline-dialogue"
style={{
left: `${(index / dialogueBuckets.length) * 100}%`,
height: `${Math.max(2, density * 8)}px`,
opacity: 0.25 + density * 0.55,
}}
/>
) : null,
)}
{itemChapters?.map((chapter, index) => (
<span
key={`chapter-${chapter.StartPositionTicks ?? index}`}
className="video-player-timeline-chapter"
style={{
left: `${((chapter.StartPositionTicks ?? 0) / (itemDuration || 1)) * 100}%`,
}}
title={chapter.Name ?? undefined}
/>
))}
</div>
<Slider
value={isUserSeeking ? seekValue : currentTime}
max={itemDuration ?? 0}
step={1}
onChange={(_, newValue) => {
// setIsUserSeeking(true);
Array.isArray(newValue)
? handleStartSeek(newValue[0])
: handleStartSeek(newValue);
}}
onChangeCommitted={(_, newValue) => {
// setIsUserSeeking(false);
// Array.isArray(newValue)
// ? setSeekValue(newValue[0])
// : setSeekValue(newValue);
if (Array.isArray(newValue)) {
handleStopSeek(newValue[0]);
} else {
handleStopSeek(newValue);
}
}}
sx={{
"& .MuiSlider-thumb": {
width: 14,
height: 14,
transition: "0.1s ease-in-out",
opacity: 0,
"&.Mui-active": {
width: 20,
height: 20,
opacity: 1,
},
},
"&:hover .MuiSlider-thumb": {
opacity: 1,
},
},
"&:hover .MuiSlider-thumb": {
opacity: 1,
},
"& .MuiSlider-rail": {
opacity: 0.28,
background: "white",
},
}}
marks={chapterMarks}
valueLabelDisplay="off"
ref={areaRef}
onMouseMove={handleSliderHover}
/>
"& .MuiSlider-rail": {
opacity: 0.28,
background: "white",
},
}}
valueLabelDisplay="off"
ref={areaRef}
onMouseMove={handleSliderHover}
/>
</div>
</Tooltip>
);
};