Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 97 additions & 8 deletions e2e/video-controls.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,23 @@ async function withRealVideo(page: Page): Promise<void> {
await page.waitForTimeout(200);
}

// 缩略图源(thumbVideo)独立于主视频:withRealVideo 只注主视频源,e2e 下
// 缩略图源仍是 mock 路径 → 永无真帧 → 就绪门控(#1953 复测③)永不打开。
async function withRealThumbVideo(page: Page): Promise<void> {
await page.evaluate(async (b64) => {
const thumb = document.querySelector(
'[data-testid="video-thumb-source"]',
) as HTMLVideoElement | null;
if (!thumb) return;
thumb.src = `data:video/mp4;base64,${b64}`;
await new Promise<void>((resolve) => {
if (thumb.readyState >= 1) return resolve();
thumb.addEventListener("loadedmetadata", () => resolve(), { once: true });
});
}, TINY_MP4);
await page.waitForTimeout(100);
}

test("控制条顺序:上下集夹住播放键,截图→画中画", async ({ page }) => {
await openMedia(page, "/Users/test/clip.mp4");

Expand Down Expand Up @@ -264,6 +281,7 @@ test("控制条 38px、右侧按钮与图标统一尺寸", async ({ page }) => {
test("进度条悬停显示当前位置缩略图,移开消失", async ({ page }) => {
await openMedia(page, "/Users/test/clip.mp4");
await withRealVideo(page);
await withRealThumbVideo(page);
const progress = page.locator(".art-progress").first();
const box = await progress.boundingBox();
if (!box) throw new Error("进度条不可测量");
Expand All @@ -282,14 +300,18 @@ test("进度条悬停显示当前位置缩略图,移开消失", async ({ page
const gap = trackBox.y - (tb.y + tb.height);
expect(gap).toBeGreaterThanOrEqual(0);
expect(gap).toBeLessThanOrEqual(12);
// 缩略图显示时,Artplayer 自带的时间气泡隐藏——同屏只留一个时间来源(#1953)
const tipDisplay = await page.evaluate(() => {
const tip = document.querySelector(
".art-video-player .art-progress-tip",
) as HTMLElement | null;
return tip ? getComputedStyle(tip).display : "absent";
});
expect(tipDisplay).toBe("none");
// 缩略图显示时,Artplayer 自带的时间气泡隐藏——同屏只留一个时间来源(#1953)。
// 就绪门控下气泡在真帧绘入后才隐藏(等待期作即时反馈),故轮询到就绪。
await expect
.poll(() =>
page.evaluate(() => {
const tip = document.querySelector(
".art-video-player .art-progress-tip",
) as HTMLElement | null;
return tip ? getComputedStyle(tip).display : "absent";
}),
)
.toBe("none");
await page.mouse.move(box.x + box.width / 2, box.y - 80);
await expect(page.locator('[data-testid="video-thumb"]')).toHaveCount(0);
});
Expand Down Expand Up @@ -317,6 +339,73 @@ test("缩略图底边贴近可见进度轨道(#1953 复测)", async ({ page
expect(gap).toBeLessThanOrEqual(12);
});

test("缩略图等真帧就绪才亮出,无空白闪切(#1953 复测③)", async ({ page }) => {
await openMedia(page, "/Users/test/clip.mp4");
await withRealVideo(page);
await withRealThumbVideo(page);
const progress = page.locator(".art-progress").first();
const box = await progress.boundingBox();
if (!box) throw new Error("进度条不可测量");
await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2);
const thumb = page.locator('[data-testid="video-thumb"]');
await expect(thumb).toHaveCount(1);
// 弹层出现即应有真帧:空白画布全像素 alpha=0,绘帧后存在不透明像素。
// 像素级判定(而非 dataURL 长度)——纯色测试片绘帧后 PNG 同样极小压缩。
// 证明「亮出即有真帧」,而非先空白盒再被真帧替换(#1953 复测③)。
await expect
.poll(() =>
page.evaluate(() => {
const canvas = document.querySelector(
'[data-testid="video-thumb"] canvas',
) as HTMLCanvasElement | null;
const ctx = canvas?.getContext("2d");
if (!canvas || !ctx) return false;
const data = ctx.getImageData(0, 0, canvas.width, canvas.height).data;
for (let i = 3; i < data.length; i += 4) {
if (data[i] > 0) return true;
}
return false;
}),
)
.toBe(true);
await expect(thumb).toHaveCSS("opacity", "1");
const tb = (await thumb.boundingBox())!;
const trackBox = await page
.locator(".art-control-progress-inner")
.first()
.boundingBox();
if (!trackBox) throw new Error("可见进度轨道不可测量");
const gap = trackBox.y - (tb.y + tb.height);
expect(gap).toBeGreaterThan(0);
expect(gap).toBeLessThanOrEqual(12);

// 反向钉死门控语义:真帧不可得(源被卸载)时弹层必须不亮——
// 旧实现此时会亮空白盒(本用例失败),新实现保留时间气泡作反馈。
await page.mouse.move(box.x + box.width / 2, box.y - 80);
await expect(page.locator('[data-testid="video-thumb"]')).toHaveCount(0);
await page.evaluate(() => {
const thumbSource = document.querySelector(
'[data-testid="video-thumb-source"]',
) as HTMLVideoElement | null;
thumbSource?.removeAttribute("src");
thumbSource?.load();
});
await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2);
await expect(page.locator('[data-testid="video-thumb"]')).toHaveCount(1);
await page.waitForTimeout(400);
await expect(page.locator('[data-testid="video-thumb"]')).toHaveCSS(
"opacity",
"0",
);
const tipDisplay = await page.evaluate(() => {
const tip = document.querySelector(
".art-video-player .art-progress-tip",
) as HTMLElement | null;
return tip ? getComputedStyle(tip).display : "absent";
});
expect(tipDisplay).not.toBe("none");
});

test("全屏态仍有二级菜单", async ({ page }) => {
await openMedia(page, "/Users/test/clip.mp4");
await withRealVideo(page);
Expand Down
35 changes: 30 additions & 5 deletions src/components/Content/VideoPlayer.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { useCallback, useEffect, useRef, useState } from "react";
import {
useCallback,
useEffect,
useLayoutEffect,
useRef,
useState,
} from "react";
import { createPortal } from "react-dom";
import Artplayer from "artplayer";
import { invoke } from "@tauri-apps/api/core";
Expand Down Expand Up @@ -321,15 +327,27 @@ export default function VideoPlayer({
bottom: number;
t: number;
} | null>(null);
// #1953 复测③:弹层亮出 ≠ 真帧就绪。thumb 只携带定位,canvas 内容要等
// 异步 seek 的 onSeeked 绘入;此前弹层先以空白盒出现 ~50-300ms 再被真帧替换 = 闪切。
// thumbReady 由 onSeeked 绘帧成功后置真,弹层 opacity 与 Artplayer 时间气泡
// 隐藏都门控在它之上——等待期保留气泡作即时反馈,真帧就绪与气泡隐藏同帧原子切换。
const [thumbReady, setThumbReady] = useState(false);
const thumbActive = thumb !== null;
const thumbCanvasRef = useRef<HTMLCanvasElement | null>(null);
const thumbVideoRef = useRef<HTMLVideoElement | null>(null);
// 会话起始复位:canvas 随弹层卸载重建,旧会话 ready 残留会亮空画布;
// layout effect + setState 保证 paint 前完成复位,绝不亮空白帧。
useLayoutEffect(() => {
if (thumbActive) setThumbReady(false);
}, [thumbActive]);
// 缩略图显隐同步到 $player 类:隐藏 Artplayer 自带的时间气泡,
// 避免与缩略图同屏两处时间(#1953 复测;音频无缩略图,气泡保留)。
useEffect(() => {
// 门控 thumbReady:真帧就绪才隐藏气泡,等待期保留气泡作即时反馈。
useLayoutEffect(() => {
const player = artRef.current?.template?.$player;
if (!player) return;
player.classList.toggle("vp-thumb-show", thumb !== null);
}, [thumb]);
player.classList.toggle("vp-thumb-show", thumbActive && thumbReady);
}, [thumbActive, thumbReady]);
const [shotNotice, setShotNotice] = useState<{
text: string;
left: number;
Expand Down Expand Up @@ -1427,6 +1445,8 @@ export default function VideoPlayer({
const ctx2d = canvas.getContext("2d");
if (!ctx2d) return;
ctx2d.drawImage(thumbVideo, 0, 0, canvas.width, canvas.height);
// 先绘后置真:就绪翻转与画布内容同帧,构造上不存在「可见且空白」窗口(#1953 复测③)。
setThumbReady(true);
};
const onProgressMove = (e: MouseEvent) => {
if (!progressEl) return;
Expand Down Expand Up @@ -1458,7 +1478,10 @@ export default function VideoPlayer({
// 元数据未就绪:只显示时间
}
};
const onProgressLeave = () => setThumb(null);
const onProgressLeave = () => {
setThumb(null);
setThumbReady(false);
};
progressEl?.addEventListener("mousemove", onProgressMove);
progressEl?.addEventListener("mouseleave", onProgressLeave);
thumbVideo.addEventListener("seeked", onSeeked);
Expand Down Expand Up @@ -2795,6 +2818,8 @@ export default function VideoPlayer({
overflow: "hidden",
background: "var(--app-surface)",
boxShadow: "0 4px 16px rgba(0,0,0,0.4)",
// 就绪才亮:帧已在画布上,硬出现无闪感(不加 transition,#1953 复测③)。
opacity: thumbReady ? 1 : 0,
pointerEvents: "none",
}}
>
Expand Down
Loading