From f9869601a3167a95493ce164fcb83412c07e4ed3 Mon Sep 17 00:00:00 2001 From: xuejianwu <374601383@qq.com> Date: Thu, 30 Jul 2026 09:52:39 +0800 Subject: [PATCH] fix: fit generated videos to any aspect ratio --- public/app.js | 10 +++++++++- public/index.html | 4 ++-- public/styles.css | 5 +++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/public/app.js b/public/app.js index 3af9c21..4666c20 100644 --- a/public/app.js +++ b/public/app.js @@ -1504,15 +1504,20 @@ function renderCompletedVideo(videoUrl, mock) { if (videoUrl) { const video = document.createElement("video"); video.controls = true; + video.playsInline = true; + video.preload = "metadata"; video.src = videoUrl; + el.videoStage.classList.add("has-video"); el.videoStage.replaceChildren(video); } else { + el.videoStage.classList.remove("has-video"); el.videoStage.innerHTML = `
${mock ? "Mock 流程已完成" : "任务已完成"}${mock ? "输入客户令牌后此处展示真实视频" : "接口响应中未识别到视频 URL,请稍后重试"}
`; } updateProgress(100, "视频生成完成"); } function renderGenerationError(message) { + el.videoStage.classList.remove("has-video"); const wrapper = document.createElement("div"); wrapper.className = "generation-error"; const title = document.createElement("strong"); @@ -1533,7 +1538,10 @@ function contextualizeGenerationError(message) { return `${label}在视频接口中不存在。通常表示素材已失效、尚未同步,或不属于当前客户令牌。素材 ID:${assetMatch[0]}`; } -function resetVideoStage() { el.videoStage.innerHTML = '
Seedance 2 正在生成镜头…
'; } +function resetVideoStage() { + el.videoStage.classList.remove("has-video"); + el.videoStage.innerHTML = '
Seedance 2 正在生成镜头…
'; +} function updateProgress(value, title) { const safe = Math.max(0, Math.min(100, Number(value) || 0)); el.generationTitle.textContent = title; diff --git a/public/index.html b/public/index.html index a6d8808..8028e5c 100644 --- a/public/index.html +++ b/public/index.html @@ -4,7 +4,7 @@ 营响力|AI 短剧数字人 Demo - +
@@ -283,6 +283,6 @@ - + diff --git a/public/styles.css b/public/styles.css index 87c7efb..9b013f6 100644 --- a/public/styles.css +++ b/public/styles.css @@ -221,7 +221,8 @@ hr { border: 0; border-top: 1px solid var(--line); margin: 26px 0 0; } .generation { margin-top: 22px; padding: 16px; border-radius: 14px; border: 1px solid var(--line); background: #fafbfe; } .video-stage { aspect-ratio: 16 / 8; max-height: 430px; background: #111827; border-radius: 11px; overflow: hidden; display: grid; place-items: center; color: white; } -.video-stage video { width: 100%; height: 100%; object-fit: contain; } +.video-stage.has-video { aspect-ratio: auto; min-height: 320px; max-height: none; padding: 12px; } +.video-stage.has-video video { display: block; width: auto; max-width: 100%; height: auto; max-height: min(72vh, 760px); margin: auto; object-fit: contain; background: #111827; } .generation-error { max-width: 620px; padding: 24px; text-align: center; } .generation-error strong { display: block; color: #ffb8bd; font-size: 18px; } .generation-error p { margin: 10px 0 0; color: #d7deed; font-size: 13px; line-height: 1.65; } @@ -241,7 +242,7 @@ hr { border: 0; border-top: 1px solid var(--line); margin: 26px 0 0; } .version-card { display: grid; grid-template-columns: 116px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 10px; border: 1px solid var(--line); border-radius: 12px; background: #fafbfe; } .version-card.selected { border-color: var(--green); background: var(--green-soft); } .version-preview { width: 116px; aspect-ratio: 16 / 9; border-radius: 8px; overflow: hidden; display: grid; place-items: center; background: #111827; color: #d6dceb; font-size: 10px; } -.version-preview video { width: 100%; height: 100%; object-fit: cover; } +.version-preview video { width: 100%; height: 100%; object-fit: contain; background: #111827; } .version-copy { min-width: 0; display: grid; gap: 4px; } .version-copy strong { font-size: 13px; } .version-copy span { overflow: hidden; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }