feat: support mobile video previews

This commit is contained in:
TerryM
2026-06-01 16:35:40 +08:00
parent c53032155b
commit a968f47640
16 changed files with 275 additions and 47 deletions

View File

@@ -6,12 +6,20 @@ import { useI18n } from "../../../i18n";
import type { Attachment, Post } from "../../../types/post";
import { AttachmentDownloadPill } from "../AttachmentDownloadPill";
import { MessageInlineVideo } from "../MessageInlineVideo";
import {
useShouldUseMobilePreview,
useVideoPreviewSource,
} from "../hooks/useVideoPreviewSource";
import { useVideoPlayer } from "../overlays/VideoPlayer";
import { autolink } from "../utils/autolink";
import { CollapsibleText } from "../CollapsibleText";
import { downloadAttachment } from "../utils/downloadFile";
import { formatBytes } from "../utils/formatBytes";
import { postDisplayText } from "../utils/postText";
import {
videoMetadataPreviewSource,
videoPreviewSource,
} from "../utils/videoPreviewSource";
import { useToast } from "../../Toast";
const MAX_VISIBLE = 4;
@@ -59,9 +67,8 @@ function VideoAttachmentCard({
const [playing, setPlaying] = useState(false);
const posterUrl = attachment.posterUrl ?? attachment.thumbnailUrl;
const duration = formatDuration(attachment.durationSec);
const previewVideoUrl = attachment.url.includes("#")
? attachment.url
: `${attachment.url}#t=0.1`;
const videoSrc = useVideoPreviewSource(attachment);
const previewVideoUrl = videoMetadataPreviewSource(videoSrc);
return (
<div
@@ -208,6 +215,8 @@ function VideoListDialog({
onClose: () => void;
onPick: (attachment: Attachment) => void;
}) {
const useMobilePreview = useShouldUseMobilePreview();
useEffect(() => {
const onKey = (event: KeyboardEvent) => {
if (event.key === "Escape") onClose();
@@ -242,9 +251,9 @@ function VideoListDialog({
<div className="max-h-[70vh] overflow-y-auto p-2 [-ms-overflow-style:none] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden">
{videos.map((video, index) => {
const thumb = video.posterUrl ?? video.thumbnailUrl;
const previewVideoUrl = video.url.includes("#")
? video.url
: `${video.url}#t=0.1`;
const previewVideoUrl = videoMetadataPreviewSource(
videoPreviewSource(video, useMobilePreview),
);
const duration = formatDuration(video.durationSec);
return (
<div