@@ -132,7 +133,7 @@ export default function LinePicker({ open, onClose }: { open: boolean; onClose:
镜像线路
- huangguoai.pages.dev · 一般可直连
+ 一般可直连 · 仅游客浏览
);
- return (platform === "android" || platform === "ios")
+ return isMobile
?
{body}
:
{body};
}
diff --git a/src/components/LoginModal.tsx b/src/components/LoginModal.tsx
index d64c516..8fd380e 100644
--- a/src/components/LoginModal.tsx
+++ b/src/components/LoginModal.tsx
@@ -1,5 +1,5 @@
import { useState } from "react";
-import { api, platform } from "../api";
+import { api, isMobile } from "../api";
import type { User } from "../types";
import { useStore } from "../store";
import { Modal, Sheet } from "./ui";
@@ -68,12 +68,12 @@ export default function LoginModal() {
- 使用黄果短剧官网账号登录,登录态仅保存在本机。
+ 使用黄果短剧官网账号登录。登录、注册仅支持固定线路;镜像线路请以游客浏览。
);
- return (platform === "android" || platform === "ios")
+ return isMobile
?
setLoginOpen(false)}>{body}
:
setLoginOpen(false)} width={360}>{body};
-}
\ No newline at end of file
+}
diff --git a/src/components/Panels.tsx b/src/components/Panels.tsx
index b1b307c..cd5b698 100644
--- a/src/components/Panels.tsx
+++ b/src/components/Panels.tsx
@@ -1,5 +1,6 @@
-import { useEffect, useRef, useState } from "react";
-import { api, fmt } from "../api";
+import { useEffect, useMemo, useRef, useState } from "react";
+import { api, fmt, cover as imageCover } from "../api";
+import { handleArticleClick, sanitizeHtml } from "../html";
import type { Comment, CommentPage, Episode } from "../types";
import { useStore } from "../store";
import { Avatar, Empty } from "./ui";
@@ -157,6 +158,13 @@ export function CommentsPanel({ videoId, ep, total, kind = "video", onClose }: {
export function ArticlePanel({ title, html, cover, hot, onClose }: {
title: string; html: string; cover?: string; hot?: number; onClose: () => void;
}) {
+ const { toast, strictSecurity } = useStore();
+ const safeHtml = useMemo(() => sanitizeHtml(html), [html, strictSecurity]);
+ const openSafeLink = (url: string) => {
+ api.openUrl(url).catch(() => {
+ navigator.clipboard?.writeText(url).then(() => toast("链接已复制", "ok")).catch(() => {});
+ });
+ };
return (
@@ -167,11 +175,11 @@ export function ArticlePanel({ title, html, cover, hot, onClose }: {
- {cover &&

}
+ {cover &&
})
}
{title}
-
- {!html &&
这篇内容没有正文,可能只有图片或视频。
}
+
handleArticleClick(e, openSafeLink)} dangerouslySetInnerHTML={{ __html: safeHtml }} />
+ {!safeHtml &&
这篇内容没有正文,可能只有图片或视频。
}
);
-}
\ No newline at end of file
+}
diff --git a/src/components/PlaybackLock.tsx b/src/components/PlaybackLock.tsx
new file mode 100644
index 0000000..8f6101a
--- /dev/null
+++ b/src/components/PlaybackLock.tsx
@@ -0,0 +1,28 @@
+import { useEffect } from "react";
+import { ILockF } from "../icons";
+
+/** Shield pointer input and playback shortcuts without pausing the media. */
+export default function PlaybackLock({ active, onUnlock }: { active: boolean; onUnlock: () => void }) {
+ useEffect(() => {
+ if (!active) return;
+ const block = (e: KeyboardEvent) => {
+ const target = e.target as HTMLElement | null;
+ if (target?.closest("input, textarea, [contenteditable='true'], [data-playback-unlock]")) return;
+ const key = e.key.length === 1 ? e.key.toLowerCase() : e.key;
+ if ([" ", "Enter", "ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown", "Home", "End", "PageUp", "PageDown", "f", "t", "m", "l", "s", "c", "e"].includes(key)) {
+ e.preventDefault();
+ e.stopImmediatePropagation();
+ }
+ };
+ window.addEventListener("keydown", block, true);
+ return () => window.removeEventListener("keydown", block, true);
+ }, [active]);
+
+ return
e.stopPropagation()} onClick={e => e.stopPropagation()} onWheel={e => e.stopPropagation()}>
+
+
;
+}
diff --git a/src/components/Player.tsx b/src/components/Player.tsx
index 5856a38..b88a2a4 100644
--- a/src/components/Player.tsx
+++ b/src/components/Player.tsx
@@ -1,12 +1,17 @@
import React, { useEffect, useRef, useState } from "react";
import Hls from "hls.js";
import { fmtTime, platform, playlist } from "../api";
-import { ICompress, IExpand, IPauseF, IPlayF, IVol, IVolMute } from "../icons";
+import { mediaResource, observeHls, usePlayerDiagnostics } from "../playbackDiagnostics";
+import { usePlaybackActivity } from "../usePlaybackActivity";
+import { useSeekInput } from "../useSeekInput";
+import PlaybackLock from "./PlaybackLock";
+import { ICompress, IExpand, ILockF, IPauseF, IPlayF, IVol, IVolMute } from "../icons";
type Props = {
src: string; // 原始 m3u8 地址
poster?: string; // 已处理好的封面地址(本地协议)
autoPlay?: boolean;
+ active?: boolean;
muted?: boolean;
loop?: boolean;
onEnded?: () => void;
@@ -15,24 +20,42 @@ type Props = {
onToggleMute?: () => void;
controls?: boolean;
className?: string;
+ diagnosticContext?: Record
;
};
export default function Player({
- src, poster, autoPlay, muted = false, loop = false, onEnded, onPlaying,
- onTogglePlay, onToggleMute, controls = true, className = "",
+ src, poster, autoPlay, active = true, muted = false, loop = false, onEnded, onPlaying,
+ onTogglePlay, onToggleMute, controls = true, className = "", diagnosticContext = {},
}: Props) {
const videoRef = useRef(null);
const wrapRef = useRef(null);
const hlsRef = useRef(null);
const recoverCountRef = useRef(0);
+ const { trace, requestSeek } = usePlayerDiagnostics(videoRef, hlsRef, { view: "post_detail", ...diagnosticContext, active, resource: mediaResource(src) });
+ const activity = usePlaybackActivity(videoRef, hlsRef, { active, autoPlay: !!autoPlay, src, trace });
const [playing, setPlaying] = useState(false);
const [waiting, setWaiting] = useState(false);
const [time, setTime] = useState(0);
- const [scrubPct, setScrubPct] = useState(null);
const [duration, setDuration] = useState(0);
const [full, setFull] = useState(false);
const [rate, setRate] = useState(1);
const [errMsg, setErrMsg] = useState("");
+ const [controlsLocked, setControlsLocked] = useState(false);
+ const seek = useSeekInput({ time, duration, enabled: active && !controlsLocked, resetKey: src,
+ onInteraction: (phase, input, target, pointerTarget) => trace(`seek.input.${phase}`, { input, target, pointer_target: pointerTarget }),
+ onSeek: (target, input) => {
+ const video = videoRef.current;
+ if (!video || !activity.isActive()) return;
+ requestSeek(target, `legacy_${input}`);
+ setWaiting(true);
+ if (hlsRef.current) {
+ try { hlsRef.current.startLoad(target); } catch { /* ignore */ }
+ }
+ video.currentTime = target;
+ trace("seek.assigned", { target });
+ setTime(video.currentTime);
+ },
+ });
useEffect(() => {
const video = videoRef.current;
@@ -40,12 +63,20 @@ export default function Player({
const url = playlist(src);
recoverCountRef.current = 0;
setErrMsg("");
+ trace("source.load", { engine: Hls.isSupported() ? "hls.js" : "native", auto_play: autoPlay });
if (hlsRef.current) { hlsRef.current.destroy(); hlsRef.current = null; }
if (Hls.isSupported()) {
const hls = new Hls({
+ // 禁用从插播/内容引导 JSON 派生直连 URL 的可选功能。
+ interstitialsController: undefined,
+ contentSteeringController: undefined,
+ enableInterstitialPlayback: false,
enableWorker: platform !== "ios",
+ // Keep the same macOS seek workaround as the shared player.
+ preferManagedMediaSource: false,
+ autoStartLoad: false,
lowLatencyMode: false,
maxBufferLength: 30,
maxMaxBufferLength: 60,
@@ -60,10 +91,12 @@ export default function Player({
fragLoadingRetryDelay: 400,
});
hlsRef.current = hls;
+ observeHls(hls, trace);
hls.loadSource(url);
hls.attachMedia(video);
hls.on(Hls.Events.MANIFEST_PARSED, () => {
- if (autoPlay) video.play().catch(() => setPlaying(false));
+ if (activity.isActive()) hls.startLoad();
+ if (autoPlay) activity.play("manifest_autoplay", true);
});
hls.on(Hls.Events.FRAG_BUFFERED, () => {
recoverCountRef.current = 0;
@@ -79,6 +112,7 @@ export default function Player({
}
return;
}
+ if (!activity.isActive()) return;
if (data.type === Hls.ErrorTypes.NETWORK_ERROR && recoverCountRef.current < 4) {
recoverCountRef.current += 1;
try { hls.startLoad(video.currentTime || -1); } catch { /* ignore */ }
@@ -99,10 +133,11 @@ export default function Player({
} else {
// Safari / 部分 WebView 原生支持 HLS
video.src = url;
- if (autoPlay) video.play().catch(() => setPlaying(false));
+ if (autoPlay) activity.play("native_autoplay", true);
}
return () => {
+ trace("source.cleanup");
if (hlsRef.current) { hlsRef.current.destroy(); hlsRef.current = null; }
};
}, [src, autoPlay]);
@@ -122,21 +157,9 @@ export default function Player({
const toggle = () => {
const video = videoRef.current;
if (!video) return;
- if (video.paused) video.play().catch(() => {});
- else video.pause();
- };
-
- const commitSeek = (pctVal: number) => {
- const video = videoRef.current;
- setScrubPct(null);
- if (!video || !duration) return;
- const target = Math.max(0, Math.min(duration - 0.15, (pctVal / 1000) * duration));
- setWaiting(true);
- if (hlsRef.current) {
- try { hlsRef.current.startLoad(target); } catch { /* ignore */ }
- }
- try { video.currentTime = target; } catch { /* ignore */ }
- setTime(target);
+ trace("toggle.request");
+ if (video.paused) activity.play("toggle");
+ else activity.pause("toggle");
};
const cycleRate = () => {
@@ -154,30 +177,29 @@ export default function Player({
else el.requestFullscreen().catch(() => {});
};
- const pct = scrubPct !== null ? scrubPct / 10 : duration > 0 ? (time / duration) * 100 : 0;
- const displayTime = scrubPct !== null && duration > 0 ? (scrubPct / 1000) * duration : time;
+ const pct = duration > 0 ? (seek.time / duration) * 100 : 0;
return (
+
+ {controlsLocked &&
setControlsLocked(false)} />}
);
-}
\ No newline at end of file
+}
diff --git a/src/components/PlayerControls.tsx b/src/components/PlayerControls.tsx
index 1ef2b8e..3eb025a 100644
--- a/src/components/PlayerControls.tsx
+++ b/src/components/PlayerControls.tsx
@@ -1,6 +1,7 @@
import { useEffect, useRef, useState } from "react";
import { fmtTime } from "../api";
-import { ICheck, ICompress, IExpand, INext, IPauseF, IPip, IPlayF, ITheater, IVol, IVolMute } from "../icons";
+import { useSeekInput } from "../useSeekInput";
+import { ICheck, ICompress, IExpand, ILockF, INext, IPauseF, IPip, IPlayF, ITheater, IVol, IVolMute } from "../icons";
type Props = {
paused: boolean;
@@ -13,14 +14,18 @@ type Props = {
theater?: boolean;
fullscreen?: boolean;
visible?: boolean;
+ seekEnabled?: boolean;
+ seekKey?: string;
nextDisabled?: boolean;
nextTitle?: string;
onToggle: () => void;
- onSeek: (t: number) => void;
+ onSeek: (t: number, source?: string) => void;
+ onSeekInteraction?: (phase: string, input: string, target: number, pointerTarget?: number) => void;
onRate: (r: number) => void;
onMute: () => void;
onVolume: (v: number) => void;
onPip: () => void;
+ onLock: () => void;
onTheater?: () => void;
onFullscreen: () => void;
onNext?: () => void;
@@ -30,11 +35,13 @@ const clock = (s: number) => fmtTime(Math.max(0, s || 0)).padStart(5, "0");
export default function PlayerControls({
paused, time, duration, buffered = 0, rate, muted, volume, theater = false, fullscreen = false,
- visible = true, nextDisabled = false, nextTitle = "下一个", onToggle, onSeek, onRate, onMute, onVolume, onPip, onTheater, onFullscreen, onNext,
+ visible = true, seekEnabled = true, seekKey, nextDisabled = false, nextTitle = "下一个", onToggle, onSeek, onSeekInteraction, onRate, onMute, onVolume, onPip, onLock, onTheater, onFullscreen, onNext,
}: Props) {
const [speedOpen, setSpeedOpen] = useState(false);
const boxRef = useRef(null);
- const pct = duration ? Math.min(100, (time / duration) * 100) : 0;
+ const seek = useSeekInput({ time, duration, enabled: seekEnabled, resetKey: seekKey, onInteraction: onSeekInteraction,
+ onSeek: (target, input) => onSeek(target, `desktop_${input}`) });
+ const pct = duration ? Math.min(100, (seek.time / duration) * 100) : 0;
useEffect(() => {
if (!speedOpen) return;
@@ -46,13 +53,12 @@ export default function PlayerControls({
return (
e.stopPropagation()}>
-
+
@@ -64,7 +70,7 @@ export default function PlayerControls({
)}
-
{clock(time)}/{clock(duration)}
+
{clock(seek.time)}/{clock(duration)}
+
{!fullscreen && onTheater && (
@@ -103,4 +110,4 @@ export default function PlayerControls({
);
-}
\ No newline at end of file
+}
diff --git a/src/components/VideoSurface.tsx b/src/components/VideoSurface.tsx
index 064197a..607ec0a 100644
--- a/src/components/VideoSurface.tsx
+++ b/src/components/VideoSurface.tsx
@@ -1,13 +1,16 @@
import React, { useEffect, useImperativeHandle, useRef, forwardRef, useState } from "react";
import Hls from "hls.js";
import { isLocalMedia, platform, playlist } from "../api";
+import { mediaResource, observeHls, usePlayerDiagnostics } from "../playbackDiagnostics";
+import { usePlaybackActivity } from "../usePlaybackActivity";
export type VideoHandle = {
el: () => HTMLVideoElement | null;
play: () => void;
pause: () => void;
toggle: () => void;
- seek: (t: number, autoResume?: boolean) => void;
+ seek: (t: number, sourceOrAutoResume?: string | boolean) => void;
+ trace: (event: string, data?: Record
) => void;
rate: (r: number) => void;
mute: (m: boolean) => void;
volume: (v: number) => void;
@@ -18,6 +21,8 @@ type Props = {
src: string;
poster?: string;
autoPlay?: boolean;
+ active?: boolean;
+ diagnosticContext?: Record;
muted?: boolean;
loop?: boolean;
fit?: "contain" | "cover";
@@ -43,7 +48,7 @@ type Props = {
/** 只负责「播」:hls.js + video 元素,控制条由外层渲染。 */
const VideoSurface = forwardRef(function VideoSurface(
- { src, poster, autoPlay = true, muted = false, loop = false, fit = "contain",
+ { src, poster, autoPlay = true, active = true, diagnosticContext = {}, muted = false, loop = false, fit = "contain",
scale = 1, panX = 0, panY = 0, isGesturing = false,
volume = 1, rate = 1,
onTime, onDuration, onSize, onPlaying, onPause, onWaiting, onEnded, onError, onClick, className = "" },
@@ -55,6 +60,8 @@ const VideoSurface = forwardRef(function VideoSurface(
const recoverTimerRef = useRef(null);
const lastSizeRef = useRef({ w: 0, h: 0 });
const [ready, setReady] = useState(false);
+ const { trace, requestSeek } = usePlayerDiagnostics(videoRef, hlsRef, { ...diagnosticContext, active, resource: mediaResource(src) });
+ const activity = usePlaybackActivity(videoRef, hlsRef, { active, autoPlay, src, trace });
const reportSizeAndDuration = (v: HTMLVideoElement) => {
if (v.duration && Number.isFinite(v.duration) && v.duration > 0) {
@@ -68,12 +75,15 @@ const VideoSurface = forwardRef(function VideoSurface(
}
};
- const safeSeek = (t: number, autoResume = false) => {
+ const safeSeek = (t: number, sourceOrAutoResume: string | boolean = "handle") => {
const v = videoRef.current;
if (!v || !Number.isFinite(t)) return;
const dur = v.duration && Number.isFinite(v.duration) ? v.duration : 0;
const target = dur > 0 ? Math.max(0, Math.min(dur - 0.15, t)) : Math.max(0, t);
+ const source = typeof sourceOrAutoResume === "string" ? sourceOrAutoResume : "handle";
+ const autoResume = typeof sourceOrAutoResume === "boolean" ? sourceOrAutoResume : !v.paused;
+ requestSeek(target, source);
onWaiting?.();
if (hlsRef.current) {
try {
@@ -83,19 +93,22 @@ const VideoSurface = forwardRef(function VideoSurface(
try {
v.currentTime = target;
- } catch { /* ignore */ }
+ trace("seek.assigned", { target, source });
+ } catch (e) {
+ trace("seek.rejected", { error_name: (e as Error).name });
+ }
- if (autoResume) {
+ if (autoResume && activity.isActive()) {
const resumeOnce = () => {
v.removeEventListener("seeked", resumeOnce);
v.removeEventListener("canplay", resumeOnce);
- v.play().catch(() => {});
+ if (activity.isActive()) v.play().catch(() => {});
};
v.addEventListener("seeked", resumeOnce, { once: true });
v.addEventListener("canplay", resumeOnce, { once: true });
// 兜底:若 350ms 内已经就绪则直接播
window.setTimeout(() => {
- if (v.readyState >= 2 && v.paused) {
+ if (v.readyState >= 2 && v.paused && activity.isActive()) {
v.removeEventListener("seeked", resumeOnce);
v.removeEventListener("canplay", resumeOnce);
v.play().catch(() => {});
@@ -106,28 +119,16 @@ const VideoSurface = forwardRef(function VideoSurface(
useImperativeHandle(ref, () => ({
el: () => videoRef.current,
- play: () => {
- const v = videoRef.current;
- if (!v) return;
- if (hlsRef.current) {
- try { hlsRef.current.startLoad(v.currentTime || -1); } catch { /* ignore */ }
- }
- v.play().catch(() => {});
- },
- pause: () => videoRef.current?.pause(),
+ play: () => activity.play("handle"),
+ pause: () => activity.pause(),
toggle: () => {
const v = videoRef.current;
if (!v) return;
- if (v.paused) {
- if (hlsRef.current) {
- try { hlsRef.current.startLoad(v.currentTime || -1); } catch { /* ignore */ }
- }
- v.play().catch(() => {});
- } else {
- v.pause();
- }
+ trace("toggle.request");
+ if (v.paused) activity.play("toggle"); else activity.pause("toggle");
},
- seek: (t: number, autoResume = false) => safeSeek(t, autoResume),
+ seek: (t: number, sourceOrAutoResume: string | boolean = "handle") => safeSeek(t, sourceOrAutoResume),
+ trace,
rate: (r: number) => { const v = videoRef.current; if (v) v.playbackRate = r; },
mute: (m: boolean) => { const v = videoRef.current; if (v) v.muted = m; },
volume: (vol: number) => { const v = videoRef.current; if (v) v.volume = vol; },
@@ -139,7 +140,7 @@ const VideoSurface = forwardRef(function VideoSurface(
if (hlsRef.current) {
try {
hlsRef.current.startLoad(cur);
- v.play().catch(() => {});
+ activity.play("reload");
return;
} catch { /* ignore */ }
}
@@ -147,7 +148,7 @@ const VideoSurface = forwardRef(function VideoSurface(
if (cur > 0) {
try { v.currentTime = cur; } catch { /* ignore */ }
}
- v.play().catch(() => {});
+ activity.play("reload");
},
}));
@@ -167,6 +168,7 @@ const VideoSurface = forwardRef(function VideoSurface(
const url = proxied ? src : playlist(src);
const useHls = !url.includes("/seg?u=");
const isIos = platform === "ios";
+ trace("source.load", { engine: useHls && Hls.isSupported() ? "hls.js" : "native", auto_play: autoPlay, resource: mediaResource(src) });
/* 换源时先把音量/倍速套回去:hls 重新 attach 后浏览器会把它们重置成默认值 */
const applySettings = () => {
@@ -180,8 +182,15 @@ const VideoSurface = forwardRef(function VideoSurface(
if (useHls && Hls.isSupported()) {
const hls = new Hls({
+ // 禁用从插播/内容引导 JSON 派生直连 URL 的可选功能。
+ interstitialsController: undefined,
+ contentSteeringController: undefined,
+ enableInterstitialPlayback: false,
// iOS WKWebView 下 WebWorker 跨自定义协议 hg:// 高频中断易死锁,关闭 Worker 走主线程加载更稳
enableWorker: !isIos,
+ // Prefer standard MSE on macOS; hls.js handles MMS-only fallback and seek recovery.
+ preferManagedMediaSource: false,
+ autoStartLoad: false,
lowLatencyMode: false,
maxBufferLength: 30,
maxMaxBufferLength: 60,
@@ -200,10 +209,12 @@ const VideoSurface = forwardRef(function VideoSurface(
startFragPrefetch: true,
});
hlsRef.current = hls;
+ observeHls(hls, trace);
hls.loadSource(url);
hls.attachMedia(video);
hls.on(Hls.Events.MANIFEST_PARSED, () => {
- if (autoPlay) video.play().catch(() => {});
+ if (activity.isActive()) hls.startLoad();
+ if (autoPlay) activity.play("manifest_autoplay", true);
});
hls.on(Hls.Events.FRAG_BUFFERED, () => {
recoverCountRef.current = 0;
@@ -213,9 +224,11 @@ const VideoSurface = forwardRef(function VideoSurface(
// 非致命卡顿错误(常见于拖动进度条后缓冲空洞):主动触发加载与微调跳帧
if (!data.fatal) {
if (
- data.details === Hls.ErrorDetails.BUFFER_STALLED_ERROR ||
- data.details === Hls.ErrorDetails.FRAG_LOAD_ERROR ||
- data.details === Hls.ErrorDetails.FRAG_LOAD_TIMEOUT
+ activity.isActive() && (
+ data.details === Hls.ErrorDetails.BUFFER_STALLED_ERROR ||
+ data.details === Hls.ErrorDetails.FRAG_LOAD_ERROR ||
+ data.details === Hls.ErrorDetails.FRAG_LOAD_TIMEOUT
+ )
) {
try {
hls.startLoad(video.currentTime || -1);
@@ -224,6 +237,8 @@ const VideoSurface = forwardRef(function VideoSurface(
return;
}
+ if (!activity.isActive()) return;
+
// 致命错误:优先自动重连/恢复解码器,最多静默恢复 4 次,避免拖动进度条直接弹报错层
if (data.type === Hls.ErrorTypes.NETWORK_ERROR) {
if (recoverCountRef.current < 4) {
@@ -231,7 +246,7 @@ const VideoSurface = forwardRef(function VideoSurface(
const delay = 250 * recoverCountRef.current;
if (recoverTimerRef.current) window.clearTimeout(recoverTimerRef.current);
recoverTimerRef.current = window.setTimeout(() => {
- if (!hlsRef.current) return;
+ if (!hlsRef.current || !activity.isActive()) return;
try {
hlsRef.current.startLoad(video.currentTime || -1);
if (!video.paused) video.play().catch(() => {});
@@ -240,6 +255,7 @@ const VideoSurface = forwardRef(function VideoSurface(
return;
}
onError?.(`${data.type}/${data.details}`);
+ hls.startLoad();
} else if (data.type === Hls.ErrorTypes.MEDIA_ERROR) {
if (recoverCountRef.current < 4) {
recoverCountRef.current += 1;
@@ -251,6 +267,7 @@ const VideoSurface = forwardRef(function VideoSurface(
return;
}
onError?.(`${data.type}/${data.details}`);
+ hls.recoverMediaError();
} else {
onError?.(`${data.type}/${data.details}`);
hls.destroy();
@@ -259,10 +276,11 @@ const VideoSurface = forwardRef(function VideoSurface(
});
} else {
video.src = url;
- if (autoPlay) video.play().catch(() => {});
+ if (autoPlay) activity.play("native_autoplay", true);
}
return () => {
+ trace("source.cleanup");
if (recoverTimerRef.current) {
window.clearTimeout(recoverTimerRef.current);
recoverTimerRef.current = null;
@@ -313,6 +331,7 @@ const VideoSurface = forwardRef(function VideoSurface(
playsInline
webkit-playsinline="true"
preload="auto"
+ muted={muted}
loop={loop}
onClick={onClick}
className={`w-full h-full bg-black ${fit === "cover" ? "object-cover" : "object-contain"}`}
@@ -341,7 +360,7 @@ const VideoSurface = forwardRef(function VideoSurface(
}
// 借鉴 stclock1988/hghub-ios:部分 HLS 流容器标称时长比最后一个分片略长 0.5~1.2s,
// 接近片尾时提前复位准备,若卡在片尾则自动触发连播
- if (!loop && !nearEndFiredRef.current && v.duration > 5 && v.currentTime >= v.duration - 0.35) {
+ if (!loop && !nearEndFiredRef.current && activity.isActive() && v.duration > 5 && v.currentTime >= v.duration - 0.35) {
nearEndFiredRef.current = true;
onEnded?.();
}
@@ -351,11 +370,11 @@ const VideoSurface = forwardRef(function VideoSurface(
reapply(v);
reportSizeAndDuration(v);
}}
- onPlay={() => onPlaying?.()}
+ onPlay={() => { if (activity.isActive()) onPlaying?.(); }}
onPause={() => onPause?.()}
onWaiting={(e) => {
const v = e.target as HTMLVideoElement;
- if (!loop && !nearEndFiredRef.current && v.duration > 5 && v.currentTime >= v.duration - 1.5) {
+ if (!loop && !nearEndFiredRef.current && activity.isActive() && v.duration > 5 && v.currentTime >= v.duration - 1.5) {
nearEndFiredRef.current = true;
onEnded?.();
return;
@@ -366,15 +385,15 @@ const VideoSurface = forwardRef(function VideoSurface(
setReady(true);
recoverCountRef.current = 0;
reportSizeAndDuration(e.target as HTMLVideoElement);
- onPlaying?.();
+ if (activity.isActive()) onPlaying?.();
}}
onSeeking={() => onWaiting?.()}
onSeeked={() => {
const v = videoRef.current;
- if (v && !v.paused) onPlaying?.();
+ if (v && !v.paused && activity.isActive()) onPlaying?.();
}}
onEnded={() => {
- if (!nearEndFiredRef.current) {
+ if (!nearEndFiredRef.current && activity.isActive()) {
nearEndFiredRef.current = true;
onEnded?.();
}
@@ -384,4 +403,4 @@ const VideoSurface = forwardRef(function VideoSurface(
);
});
-export default VideoSurface;
\ No newline at end of file
+export default VideoSurface;
diff --git a/src/components/ui.tsx b/src/components/ui.tsx
index 913d61c..714e62a 100644
--- a/src/components/ui.tsx
+++ b/src/components/ui.tsx
@@ -60,10 +60,10 @@ export function Modal({ open, onClose, children, width = 340 }: { open: boolean;
}
/* ——— 开关 ——— */
-export function Toggle({ on, onChange, label }: { on: boolean; onChange: (b: boolean) => void; label?: string }) {
+export function Toggle({ on, onChange, label, disabled = false }: { on: boolean; onChange: (b: boolean) => void; label?: string; disabled?: boolean }) {
return (
-
);
-}
\ No newline at end of file
+}
diff --git a/src/pages/Home.tsx b/src/pages/Home.tsx
index 93e7758..dda40f6 100644
--- a/src/pages/Home.tsx
+++ b/src/pages/Home.tsx
@@ -1,22 +1,25 @@
import { useCallback, useEffect, useRef, useState } from "react";
import Feed from "../components/Feed";
-import { api, platform } from "../api";
+import { api } from "../api";
import type { VideoCard } from "../types";
import { useStore } from "../store";
-import { ISearch, IVol, IVolMute } from "../icons";
+import { ISearch } from "../icons";
+import { Empty } from "../components/ui";
export default function Home({ active, bottomInset }: { active: boolean; bottomInset: number }) {
- const { muted, setMuted, setTab, toast, fs } = useStore();
+ const { toast } = useStore();
const [items, setItems] = useState
([]);
const [page, setPage] = useState(1);
const [loading, setLoading] = useState(false);
const [done, setDone] = useState(false);
+ const [error, setError] = useState("");
const loadingRef = useRef(false);
const load = useCallback(async (p: number) => {
if (loadingRef.current || done) return;
loadingRef.current = true;
setLoading(true);
+ setError("");
try {
const res = await api.feed(p, 10);
const list = res?.items || [];
@@ -27,7 +30,9 @@ export default function Home({ active, bottomInset }: { active: boolean; bottomI
setPage(p);
if (!list.length || (res?.pagination && p >= res.pagination.pages)) setDone(true);
} catch (e) {
- toast((e as Error).message || "加载失败", "info");
+ const message = (e as Error).message || "加载失败";
+ setError(message);
+ toast(message, "info");
} finally {
loadingRef.current = false;
setLoading(false);
@@ -43,25 +48,15 @@ export default function Home({ active, bottomInset }: { active: boolean; bottomI
{items.length ? (
{ if (!loading && !done) load(page + 1); }} />
+ ) : !loading && error ? (
+
+ } title="首页加载失败" sub={error} action="重试" onAction={() => void load(1)} />
+
+ ) : !loading && done ? (
+ } title="暂无视频" />
) : (
)}
-
- {/* 移动端:静音 + 搜索(压在视频上,固定白字 + 半透明黑底) */}
- {(platform === "android" || platform === "ios") && !fs && (
-
-
- setMuted((m) => !m)} aria-label={muted ? "取消静音" : "静音"}
- className="hg-chip pointer-events-auto w-9 h-9 rounded-full flex items-center justify-center pressable elev-1">
- {muted ? : }
-
- setTab("search")} aria-label="搜索"
- className="hg-chip pointer-events-auto w-9 h-9 rounded-full flex items-center justify-center pressable elev-1">
-
-
-
-
- )}
);
-}
\ No newline at end of file
+}
diff --git a/src/pages/Posts.tsx b/src/pages/Posts.tsx
index db3dc75..73f8c42 100644
--- a/src/pages/Posts.tsx
+++ b/src/pages/Posts.tsx
@@ -1,11 +1,11 @@
-import { useEffect, useRef, useState } from "react";
-import { api, cover, fmt, platform } from "../api";
+import { useEffect, useMemo, useRef, useState } from "react";
+import { api, cover, fmt, isMobile } from "../api";
import type { Post } from "../types";
import { useStore } from "../store";
import { Empty, Img } from "../components/ui";
import Player from "../components/Player";
import { IBack, IFireF, IPlayF } from "../icons";
-import { sanitizeHtml } from "../html";
+import { handleArticleClick, sanitizeHtml } from "../html";
/* ================= 吃瓜列表 ================= */
export function PostsPage({ onBack, wide }: { onBack: () => void; wide: boolean }) {
@@ -86,11 +86,18 @@ export function PostsPage({ onBack, wide }: { onBack: () => void; wide: boolean
const isHtml = (s: string) => /<(p|div|br|img|h[1-6]|ul|ol|li|blockquote|span|strong|em)\b/i.test(s);
/* ================= 吃瓜详情(网页式浏览) ================= */
-export function PostDetail({ id, onBack }: { id: number; onBack: () => void }) {
- const { toast } = useStore();
+export function PostDetail({ id, onBack, active = true }: { id: number; onBack: () => void; active?: boolean }) {
+ const { toast, strictSecurity, muted, setMuted } = useStore();
const [post, setPost] = useState<(Post & { content?: string; video_url?: string }) | null>(null);
const [err, setErr] = useState