Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

♻️ refactor(chat): render message videos with the LobeUI Video player (#22272)

Lobehub Coder24423a2d1165
diff --git a/locales/en-US/common.json b/locales/en-US/common.json
index 0fe87c8bf70..029d6b302e0 100644
--- a/locales/en-US/common.json
+++ b/locales/en-US/common.json
@@ -387,6 +387,7 @@
"ok": "OK",
"openOnRight": "Open on the right",
"openOnRightHint": "Release to open side-by-side on the right",
+ "openOriginalFile": "Open original file",
"operationFailed": "Operation failed, please try again",
"or": "or",
"pageSizeItem": "{{count}} items",
diff --git a/locales/zh-CN/common.json b/locales/zh-CN/common.json
index 2fe697741b2..b63691a36e0 100644
--- a/locales/zh-CN/common.json
+++ b/locales/zh-CN/common.json
@@ -387,6 +387,7 @@
"ok": "确认",
"openOnRight": "在右侧打开",
"openOnRightHint": "松开以在右侧并排打开",
+ "openOriginalFile": "打开原文件",
"operationFailed": "操作失败,请重试",
"or": "或",
"pageSizeItem": "{{count}} 个条目",
diff --git a/packages/builtin-tool-video-generation/src/client/Render/GenerateVideo.tsx b/packages/builtin-tool-video-generation/src/client/Render/GenerateVideo.tsx
index 9c66a4e1f1d..e97a2c87df9 100644
--- a/packages/builtin-tool-video-generation/src/client/Render/GenerateVideo.tsx
+++ b/packages/builtin-tool-video-generation/src/client/Render/GenerateVideo.tsx
@@ -1,12 +1,11 @@
'use client';
import type { BuiltinRenderProps, VideoGenerationAsset } from '@lobechat/types';
-import { Block } from '@lobehub/ui';
-import { Alert, Button, Text } from '@lobehub/ui';
-import { createStaticStyles, cssVar } from '@lobehub/ui';
+import { Alert, Block, Button, createStaticStyles, cssVar, Text } from '@lobehub/ui';
import { memo, useCallback, useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
+import MessageVideo from '@/components/MessageVideo';
import { useClientDataSWR } from '@/libs/swr';
import { videoKeys } from '@/libs/swr/keys';
import { normalizeAsyncError } from '@/libs/swr/normalizeError';
@@ -32,6 +31,7 @@ const styles = createStaticStyles(({ css, cssVar }) => ({
justify-content: center;
min-height: 180px;
+ padding: 12px;
background: ${cssVar.colorFillTertiary};
`,
@@ -100,12 +100,6 @@ const styles = createStaticStyles(({ css, cssVar }) => ({
background: ${cssVar.colorFillTertiary};
`,
- video: css`
- display: block;
- width: 100%;
- max-height: 560px;
- background: ${cssVar.colorFillTertiary};
- `,
}));
const isTerminalStatus = (status?: string) => status === 'success' || status === 'error';
@@ -241,7 +235,7 @@ export const GenerateVideoRender = memo<
</div>
{url ? (
<div className={styles.body}>
- <video controls className={styles.video} poster={poster} preload={'metadata'} src={url} />
+ <MessageVideo maxHeight={560} poster={poster} src={url} />
</div>
) : (
<div className={styles.statusBody}>
diff --git a/packages/builtin-tool-video-generation/src/client/Render/GetVideoGenerationStatus.tsx b/packages/builtin-tool-video-generation/src/client/Render/GetVideoGenerationStatus.tsx
index 1f1137a61c4..3f771a52df2 100644
--- a/packages/builtin-tool-video-generation/src/client/Render/GetVideoGenerationStatus.tsx
+++ b/packages/builtin-tool-video-generation/src/client/Render/GetVideoGenerationStatus.tsx
@@ -1,12 +1,12 @@
'use client';
import type { BuiltinRenderProps, VideoGenerationAsset } from '@lobechat/types';
-import { Block } from '@lobehub/ui';
-import { Alert, Text } from '@lobehub/ui';
-import { createStaticStyles } from '@lobehub/ui';
+import { Alert, Block, createStaticStyles, Text } from '@lobehub/ui';
import { memo } from 'react';
import { useTranslation } from 'react-i18next';
+import MessageVideo from '@/components/MessageVideo';
+
import type { GetVideoGenerationStatusParams, GetVideoGenerationStatusState } from '../../types';
const styles = createStaticStyles(({ css, cssVar }) => ({
@@ -21,12 +21,6 @@ const styles = createStaticStyles(({ css, cssVar }) => ({
font-size: 12px;
color: ${cssVar.colorTextSecondary};
`,
- video: css`
- width: 100%;
- max-height: 560px;
- border-radius: 8px;
- background: ${cssVar.colorFillTertiary};
- `,
}));
const getAssetUrl = (state?: GetVideoGenerationStatusState) => {
@@ -64,15 +58,7 @@ export const GetVideoGenerationStatusRender = memo<
<Text as={'span'} className={styles.status}>
{t(`builtins.lobe-video-generation.render.status.${pluginState.status}`)}
</Text>
- {url && (
- <video
- controls
- className={styles.video}
- poster={getPosterUrl(pluginState)}
- preload={'metadata'}
- src={url}
- />
- )}
+ {url && <MessageVideo maxHeight={560} poster={getPosterUrl(pluginState)} src={url} />}
</div>
</Block>
);
diff --git a/packages/locales/src/default/common.ts b/packages/locales/src/default/common.ts
index c37576a26e7..09047197b5d 100644
--- a/packages/locales/src/default/common.ts
+++ b/packages/locales/src/default/common.ts
@@ -426,6 +426,7 @@ export default {
"Can't delete: this includes other members' topics, comments, or tasks. Ask a workspace owner to delete it.",
'manageOnlyCreator': 'Only the creator or a workspace owner can do this',
'openOnRight': 'Open on the right',
+ 'openOriginalFile': 'Open original file',
'openOnRightHint': 'Release to open side-by-side on the right',
'operationFailed': 'Operation failed, please try again',
'addNew': 'Add new',
diff --git a/src/components/MessageVideo/index.tsx b/src/components/MessageVideo/index.tsx
new file mode 100644
index 00000000000..4c553185c29
--- /dev/null
+++ b/src/components/MessageVideo/index.tsx
@@ -0,0 +1,71 @@
+'use client';
+
+import { Video } from '@lobehub/ui';
+import * as stylex from '@stylexjs/stylex';
+import { ExternalLink } from 'lucide-react';
+import { memo } from 'react';
+import { useTranslation } from 'react-i18next';
+
+// Mirrors the @lobehub/ui (6.15) Video control-bar button style, which the library does not export.
+const styles = stylex.create({
+ action: {
+ cursor: 'pointer',
+ display: 'inline-flex',
+ flex: 'none',
+ alignItems: 'center',
+ justifyContent: 'center',
+ minWidth: 28,
+ height: 28,
+ padding: 0,
+ borderRadius: 6,
+ color: 'inherit',
+ backgroundColor: { ':hover': '#ffffff1f', 'default': 'transparent' },
+ outline: { ':focus-visible': '2px solid #fff9', 'default': 'none' },
+ },
+});
+
+export interface MessageVideoProps {
+ maxHeight?: number;
+ poster?: string;
+ src: string;
+}
+
+/**
+ * Inline video player for conversation messages and tool renders, built on the
+ * @lobehub/ui Video player with an open-original-file action.
+ */
+const MessageVideo = memo<MessageVideoProps>(({ maxHeight = 400, poster, src }) => {
+ const { t } = useTranslation('common');
+
+ return (
+ <Video.Root maxHeight={maxHeight} poster={poster} src={src}>
+ <Video.Frame>
+ <Video.Caption />
+ <Video.CenterPlay />
+ <Video.Controls
+ extra={
+ // Stored files are served cross-origin, where `download` is ignored, so open the
+ // original in a new tab and let the browser save it from there.
+ <a
+ aria-label={t('openOriginalFile')}
+ {...stylex.props(styles.action)}
+ href={src}
+ rel="noreferrer"
+ target="_blank"
+ title={t('openOriginalFile')}
+ >
+ <ExternalLink size={15} />
+ </a>
+ }
+ >
+ <Video.Timeline />
+ </Video.Controls>
+ <Video.LoadError />
+ </Video.Frame>
+ </Video.Root>
+ );
+});
+
+MessageVideo.displayName = 'MessageVideo';
+
+export default MessageVideo;
diff --git a/src/features/Conversation/Messages/User/components/VideoFileListViewer.tsx b/src/features/Conversation/Messages/User/components/VideoFileListViewer.tsx
index 9b124dea9c3..31e4c3df619 100644
--- a/src/features/Conversation/Messages/User/components/VideoFileListViewer.tsx
+++ b/src/features/Conversation/Messages/User/components/VideoFileListViewer.tsx
@@ -1,6 +1,7 @@
import { Flexbox } from '@lobehub/ui';
import { memo } from 'react';
+import MessageVideo from '@/components/MessageVideo';
import { type ChatVideoItem } from '@/types/index';
interface VideoFileListViewerProps {
@@ -11,18 +12,7 @@ const VideoFileListViewer = memo<VideoFileListViewerProps>(({ items }) => {
return (
<Flexbox gap={8}>
{items.map((item) => (
- <video
- controls
- key={item.id}
- style={{
- borderRadius: 8,
- maxHeight: 400,
- maxWidth: '100%',
- }}
- >
- <source src={item.url} />
- {item.alt}
- </video>
+ <MessageVideo key={item.id} maxHeight={400} src={item.url} />
))}
</Flexbox>
);