Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b465706daa |
@@ -0,0 +1,189 @@
|
||||
name: Build iOS IPA
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches: ["main"]
|
||||
tags: ["v*"]
|
||||
|
||||
jobs:
|
||||
ios:
|
||||
name: iOS Build (IPA)
|
||||
runs-on: macos-latest
|
||||
permissions:
|
||||
contents: write
|
||||
env:
|
||||
APPLE_DEVELOPMENT_TEAM: "ABCDE12345"
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: 对齐版本号
|
||||
id: ver
|
||||
shell: bash
|
||||
run: |
|
||||
if [[ "$GITHUB_REF" == refs/tags/v* ]]; then
|
||||
V="${GITHUB_REF_NAME#v}"
|
||||
else
|
||||
V="$(node -p "require('./src-tauri/tauri.conf.json').version")"
|
||||
fi
|
||||
echo "version=$V" >> "$GITHUB_OUTPUT"
|
||||
node -e "const fs=require('fs');for(const p of ['src-tauri/tauri.conf.json','package.json']){const j=JSON.parse(fs.readFileSync(p));j.version=process.argv[1];fs.writeFileSync(p,JSON.stringify(j,null,2)+'\n')}" "$V"
|
||||
|
||||
- uses: pnpm/action-setup@v4
|
||||
with:
|
||||
version: 10
|
||||
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 22
|
||||
cache: pnpm
|
||||
|
||||
- uses: dtolnay/rust-toolchain@stable
|
||||
with:
|
||||
targets: aarch64-apple-ios,aarch64-apple-ios-sim
|
||||
|
||||
- uses: swatinem/rust-cache@v2
|
||||
with:
|
||||
workspaces: src-tauri -> target
|
||||
key: ios-build
|
||||
|
||||
- name: 安装依赖
|
||||
run: pnpm install --frozen-lockfile
|
||||
|
||||
- name: 初始化 iOS Xcode 工程
|
||||
run: |
|
||||
pnpm tauri ios init --ci || pnpm tauri ios init
|
||||
# 确保 iOS Info.plist(含 ~iphone / ~ipad 变体)支持横竖屏切换及 ATS
|
||||
for plist in $(find src-tauri/gen/apple -name "Info.plist" 2>/dev/null); do
|
||||
for key in "UISupportedInterfaceOrientations" "UISupportedInterfaceOrientations~iphone" "UISupportedInterfaceOrientations~ipad"; do
|
||||
/usr/libexec/PlistBuddy -c "Delete :${key}" "$plist" 2>/dev/null || true
|
||||
/usr/libexec/PlistBuddy -c "Add :${key} array" "$plist"
|
||||
/usr/libexec/PlistBuddy -c "Add :${key}:0 string UIInterfaceOrientationPortrait" "$plist"
|
||||
/usr/libexec/PlistBuddy -c "Add :${key}:1 string UIInterfaceOrientationLandscapeLeft" "$plist"
|
||||
/usr/libexec/PlistBuddy -c "Add :${key}:2 string UIInterfaceOrientationLandscapeRight" "$plist"
|
||||
done
|
||||
/usr/libexec/PlistBuddy -c "Delete :NSAppTransportSecurity" "$plist" 2>/dev/null || true
|
||||
/usr/libexec/PlistBuddy -c "Add :NSAppTransportSecurity dict" "$plist"
|
||||
/usr/libexec/PlistBuddy -c "Add :NSAppTransportSecurity:NSAllowsArbitraryLoads bool true" "$plist"
|
||||
done
|
||||
env:
|
||||
APPLE_DEVELOPMENT_TEAM: "ABCDE12345"
|
||||
|
||||
- name: 构建 iOS 应用与打包 IPA
|
||||
shell: bash
|
||||
env:
|
||||
APPLE_DEVELOPMENT_TEAM: "ABCDE12345"
|
||||
run: |
|
||||
V="${{ steps.ver.outputs.version }}"
|
||||
mkdir -p artifacts
|
||||
|
||||
# 1. 确保前端编译产物就绪
|
||||
pnpm build
|
||||
|
||||
# 2. 执行 Tauri iOS 自动化构建(免证书签名,激活 custom-protocol 确保为生产打包模式)
|
||||
echo "=== 执行 Tauri iOS 构建 (--no-sign --features custom-protocol) ==="
|
||||
pnpm tauri ios build --no-sign --ci --features custom-protocol || true
|
||||
|
||||
# 3. 检查是否已直接生成 IPA
|
||||
IPA_PATH=$(find src-tauri/gen/apple -name "*.ipa" 2>/dev/null | head -n 1 || true)
|
||||
if [ -n "$IPA_PATH" ] && [ -f "$IPA_PATH" ]; then
|
||||
echo "=== 发现生成的 IPA: $IPA_PATH ==="
|
||||
cp "$IPA_PATH" "artifacts/HGhub_${V}_ios.ipa"
|
||||
fi
|
||||
|
||||
# 4. 若未直接生成 IPA,寻找 .app 或通过 xcodebuild 归档编译
|
||||
if [ ! -s "artifacts/HGhub_${V}_ios.ipa" ]; then
|
||||
APP_PATH=$(find src-tauri/gen/apple -name "*.app" -type d 2>/dev/null | head -n 1 || true)
|
||||
if [ -z "$APP_PATH" ]; then
|
||||
echo "=== 未在 gen/apple 找到 .app,调用 xcodebuild 编译 Release ==="
|
||||
PROJECT_PATH=$(find src-tauri/gen/apple -name "*.xcodeproj" 2>/dev/null | head -n 1 || true)
|
||||
SCHEME_NAME=$(xcodebuild -list -project "$PROJECT_PATH" 2>/dev/null | awk '/Schemes:/{flag=1;next} flag && NF{print $1;exit}' || true)
|
||||
if [ -z "$SCHEME_NAME" ]; then
|
||||
SCHEME_NAME="huangguo-client_iOS"
|
||||
fi
|
||||
echo "项目: $PROJECT_PATH, Scheme: $SCHEME_NAME"
|
||||
xcodebuild build \
|
||||
-project "$PROJECT_PATH" \
|
||||
-scheme "$SCHEME_NAME" \
|
||||
-configuration Release \
|
||||
-destination "generic/platform=iOS" \
|
||||
CODE_SIGNING_ALLOWED=NO \
|
||||
CODE_SIGNING_REQUIRED=NO \
|
||||
CODE_SIGN_IDENTITY="" \
|
||||
-derivedDataPath build_output
|
||||
APP_PATH=$(find build_output -name "*.app" -type d 2>/dev/null | head -n 1 || true)
|
||||
fi
|
||||
|
||||
if [ -n "$APP_PATH" ] && [ -d "$APP_PATH" ]; then
|
||||
echo "=== 打包 APP 目录: $APP_PATH 为 IPA ==="
|
||||
rm -rf Payload
|
||||
mkdir -p Payload
|
||||
cp -r "$APP_PATH" Payload/
|
||||
zip -qr "artifacts/HGhub_${V}_ios.ipa" Payload
|
||||
rm -rf Payload
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -s "artifacts/HGhub_${V}_ios.ipa" ]; then
|
||||
echo "=== IPA 打包成功 ==="
|
||||
ls -lh artifacts/
|
||||
|
||||
# 5. 校验 IPA 是否为真正的生产包(验证不含 localhost:1420 且静态资源嵌入)
|
||||
echo "=== 校验生产包模式 ==="
|
||||
mkdir -p /tmp/verify_ipa
|
||||
unzip -q -o "artifacts/HGhub_${V}_ios.ipa" -d /tmp/verify_ipa
|
||||
BIN_PATH=$(find /tmp/verify_ipa -type f -name "HGhub" | head -n 1 || true)
|
||||
if [ -n "$BIN_PATH" ]; then
|
||||
if strings "$BIN_PATH" | grep -q "localhost:1420"; then
|
||||
echo "::error::警告:构建产物依然包含 localhost:1420,处于 dev 模式!"
|
||||
exit 1
|
||||
fi
|
||||
echo "=== 生产模式校验通过:未包含 devUrl,静态前端资源已内置 ==="
|
||||
fi
|
||||
rm -rf /tmp/verify_ipa
|
||||
else
|
||||
echo "::error::未能生成有效的 iOS IPA 文件"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: 上传 IPA 产物
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: HGhub-iOS-IPA
|
||||
path: artifacts/*
|
||||
if-no-files-found: error
|
||||
|
||||
- name: 发布 iOS GitHub Release
|
||||
shell: bash
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
V="${{ steps.ver.outputs.version }}"
|
||||
TAG="v${V}-ios"
|
||||
NOTES="## HGhub iOS 增强版 (v${V})
|
||||
|
||||
### ✨ 核心特性
|
||||
- **沉浸式竖屏刷剧流**:支持首页无限推荐流、题材分类、三大榜单(热门/推荐/潜力)、搜索、吃瓜社区图文与视频帖、选集与历史续播。
|
||||
- **原生横竖屏智能切换**:横屏视频支持一键「横屏全屏」(调用 iOS 原生屏幕方向旋转),支持手机物理横置自动全屏、竖回自动退出,独立固定舞台层渲染不跑偏、不闪封面。
|
||||
- **丰富触控手势**:
|
||||
- **双指自由缩放(1x~4x)与平移**:竖屏观看横屏视频可自由缩放,并提供「放大铺满 / 完整适应 / 还原缩放」胶囊按钮;
|
||||
- **单击清屏 / 双击暂停**:单击屏幕隐藏所有控件与遮罩纯享画面,双击屏幕暂停/播放;
|
||||
- **长按 2.0x 倍速 + 上滑锁定**:长按画面开启 2.0x 倍速,上滑即可锁定倍速;
|
||||
- **左右横滑预览定位**:任意位置横滑精准跳转进度。
|
||||
- **HLS 播放稳定性加固**:内置 AES Key 与分片内存缓存、拖动进度条防卡死自愈重连、全屏旋转过渡期持续保活与片尾自动连播下一集。
|
||||
- **多线路与镜像测速**:内置固定主备线路 + 自动抓取最新镜像域名 + 一键延迟测速切换。
|
||||
|
||||
### 📲 安装说明(免证书生产包 \`.ipa\`)
|
||||
1. **TrollStore(巨魔商店)**:下载 \`HGhub_${V}_ios.ipa\` 后直接导入巨魔永久安装。
|
||||
2. **AltStore / SideStore / Sideloadly**:使用个人 Apple ID 自签安装。
|
||||
3. **轻松签(ESign)/ 牛蛙助手 / Feather / 全能签**:导入证书签名后直接安装。"
|
||||
|
||||
if gh release view "$TAG" >/dev/null 2>&1; then
|
||||
gh release upload "$TAG" artifacts/*.ipa --clobber
|
||||
gh release edit "$TAG" --title "HGhub v${V} iOS 正式版" --notes "$NOTES" --prerelease=false --latest
|
||||
else
|
||||
gh release create "$TAG" artifacts/*.ipa \
|
||||
--title "HGhub v${V} iOS 正式版" \
|
||||
--notes "$NOTES" \
|
||||
--latest
|
||||
fi
|
||||
@@ -0,0 +1,147 @@
|
||||
name: Build macOS Release
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches: ["main"]
|
||||
|
||||
jobs:
|
||||
macos:
|
||||
name: macOS (${{ matrix.name }})
|
||||
runs-on: macos-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- target: aarch64-apple-darwin
|
||||
name: Apple Silicon (arm64)
|
||||
arch: arm64
|
||||
- target: x86_64-apple-darwin
|
||||
name: Intel (x64)
|
||||
arch: x64
|
||||
- target: universal-apple-darwin
|
||||
name: Universal (通用版)
|
||||
arch: universal
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: 对齐版本号
|
||||
id: ver
|
||||
shell: bash
|
||||
run: |
|
||||
if [[ "$GITHUB_REF" == refs/tags/v* ]]; then
|
||||
V="${GITHUB_REF_NAME#v}"
|
||||
else
|
||||
V="$(node -p "require('./src-tauri/tauri.conf.json').version")"
|
||||
fi
|
||||
echo "version=$V" >> "$GITHUB_OUTPUT"
|
||||
node -e "const fs=require('fs');for(const p of ['src-tauri/tauri.conf.json','package.json']){const j=JSON.parse(fs.readFileSync(p));j.version=process.argv[1];fs.writeFileSync(p,JSON.stringify(j,null,2)+'\n')}" "$V"
|
||||
|
||||
- uses: pnpm/action-setup@v4
|
||||
with:
|
||||
version: 10
|
||||
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 22
|
||||
cache: pnpm
|
||||
|
||||
- uses: dtolnay/rust-toolchain@stable
|
||||
with:
|
||||
targets: aarch64-apple-darwin,x86_64-apple-darwin
|
||||
|
||||
- uses: swatinem/rust-cache@v2
|
||||
with:
|
||||
workspaces: src-tauri -> target
|
||||
key: macos-${{ matrix.target }}
|
||||
|
||||
- name: 安装前端依赖
|
||||
run: pnpm install --frozen-lockfile
|
||||
|
||||
- name: 构建 macOS 应用 (DMG + APP)
|
||||
run: |
|
||||
pnpm tauri build --config src-tauri/tauri.macos.conf.json --target ${{ matrix.target }}
|
||||
|
||||
- name: 整理构建产物
|
||||
shell: bash
|
||||
run: |
|
||||
V="${{ steps.ver.outputs.version }}"
|
||||
mkdir -p artifacts
|
||||
|
||||
# 收集 dmg 安装包
|
||||
found_dmg=0
|
||||
for f in $(find src-tauri/target -name '*.dmg'); do
|
||||
echo "发现 DMG: $f"
|
||||
cp "$f" "artifacts/HGhub_${V}_${{ matrix.arch }}.dmg"
|
||||
found_dmg=1
|
||||
done
|
||||
|
||||
# 打包 .app 绿色压缩包(便于不需要 DMG 安装的用户直接拖拽)
|
||||
for app in $(find src-tauri/target -name 'HGhub.app' -type d); do
|
||||
echo "发现 APP: $app"
|
||||
tar -czf "artifacts/HGhub_${V}_${{ matrix.arch }}.app.tar.gz" -C "$(dirname "$app")" "HGhub.app"
|
||||
done
|
||||
|
||||
ls -lh artifacts/
|
||||
if [ "$found_dmg" -eq 0 ]; then
|
||||
echo "::error::未找到 DMG 构建产物"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: 上传构建产物
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: HGhub-macOS-${{ matrix.arch }}
|
||||
path: artifacts/*
|
||||
if-no-files-found: error
|
||||
|
||||
publish-release:
|
||||
name: 发布 GitHub Release
|
||||
needs: [macos]
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: 下载所有 macOS 产物
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
path: artifacts
|
||||
merge-multiple: true
|
||||
|
||||
- name: 查看产物列表
|
||||
run: ls -lh artifacts
|
||||
|
||||
- name: 获取版本号
|
||||
id: ver
|
||||
run: |
|
||||
V="$(node -p "require('./src-tauri/tauri.conf.json').version")"
|
||||
echo "version=$V" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: 发布 Release
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
tag_name: v${{ steps.ver.outputs.version }}-macos
|
||||
name: HGhub v${{ steps.ver.outputs.version }} macOS 专属版
|
||||
body: |
|
||||
## HGhub macOS 编译发布版 (v${{ steps.ver.outputs.version }})
|
||||
|
||||
本项目为 [Minireel/HGhub](https://github.com/Minireel/HGhub) 官方源码针对 macOS 平台的编译产物。
|
||||
原项目已在 PR #1 完成 macOS 适配支持,但官方尚未在 Release 页面发布 Mac 版产物。
|
||||
|
||||
### 下载说明
|
||||
- **Apple Silicon (M1/M2/M3/M4 系列芯片)**: 推荐下载 `HGhub_${{ steps.ver.outputs.version }}_arm64.dmg`
|
||||
- **Intel 芯片**: 推荐下载 `HGhub_${{ steps.ver.outputs.version }}_x64.dmg`
|
||||
- **通用双架构版 (全机型支持)**: 推荐下载 `HGhub_${{ steps.ver.outputs.version }}_universal.dmg`
|
||||
|
||||
### macOS 首次打开说明(绕过未签名提示)
|
||||
由于开源个人构建未购买苹果开发者企业证书签名与公证,首次打开若提示“已损坏”或“无法打开”,请在「终端」中执行以下命令清除隔离属性:
|
||||
```bash
|
||||
sudo xattr -rd com.apple.quarantine /Applications/HGhub.app
|
||||
```
|
||||
files: artifacts/*
|
||||
fail_on_unmatched_files: true
|
||||
draft: false
|
||||
prerelease: false
|
||||
@@ -3,6 +3,8 @@
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover, user-scalable=no" />
|
||||
<meta name="apple-mobile-web-app-capable" content="yes" />
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
|
||||
<meta name="theme-color" content="#1a1a1a" />
|
||||
<title>HGhub · 黄果短剧</title>
|
||||
<script>
|
||||
|
||||
@@ -11,6 +11,10 @@ rust-version = "1.90"
|
||||
name = "huangguo_client_lib"
|
||||
crate-type = ["staticlib", "cdylib", "rlib"]
|
||||
|
||||
[features]
|
||||
default = ["custom-protocol"]
|
||||
custom-protocol = ["tauri/custom-protocol"]
|
||||
|
||||
[build-dependencies]
|
||||
tauri-build = { version = "2", features = [] }
|
||||
|
||||
|
||||
@@ -43,6 +43,9 @@
|
||||
],
|
||||
"android": {
|
||||
"minSdkVersion": 24
|
||||
},
|
||||
"iOS": {
|
||||
"developmentTeam": "ABCDE12345"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
{
|
||||
"$schema": "https://schema.tauri.app/config/2",
|
||||
"build": {
|
||||
"devUrl": null
|
||||
},
|
||||
"bundle": {
|
||||
"iOS": {
|
||||
"minimumSystemVersion": "15.0"
|
||||
|
||||
+5
-7
@@ -82,8 +82,7 @@ function StackPage({ page, onBack, wide, top, bottomInset }: {
|
||||
|
||||
/* ============ 应用主体 ============ */
|
||||
function AppBody() {
|
||||
const { platform, tab, setTab, stack, pop, loginOpen, setLoginOpen, fs, clean } = useStore();
|
||||
const isMobile = platform === "android" || platform === "ios";
|
||||
const { platform, tab, setTab, stack, pop, loginOpen, setLoginOpen, fs } = useStore();
|
||||
const mainRef = useRef<HTMLDivElement>(null);
|
||||
const [wide, setWide] = useState(!isMobile);
|
||||
const [collapsed, setCollapsed] = useState(false);
|
||||
@@ -118,7 +117,7 @@ function AppBody() {
|
||||
|
||||
const vis = (k: Tab) => (tab === k ? "absolute inset-0" : "absolute inset-0 invisible pointer-events-none");
|
||||
const pageActive = stack.length === 0 && !loginOpen;
|
||||
const bottomInset = isMobile ? (fs || clean ? 0 : 40) : 14;
|
||||
const bottomInset = isMobile ? (fs ? 0 : 40) : 14;
|
||||
/* 栈页(从搜索/分类/我的进入的播放页、图文页)没有底栏,
|
||||
底部只让出安全区。之前多留了 20px,视频底边会露出一条
|
||||
「底栏」似的窄缝(底部的压暗渐变到不了屏幕最底)。 */
|
||||
@@ -139,7 +138,7 @@ function AppBody() {
|
||||
</div>
|
||||
))}
|
||||
|
||||
{isMobile && !fs && !clean && stack.length === 0 && <TabBar />}
|
||||
{isMobile && !fs && stack.length === 0 && <TabBar />}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
@@ -216,10 +215,9 @@ function ShellInner({ collapsed, theater }: { collapsed: boolean; theater: boole
|
||||
|
||||
/* ============ 移动端(无壳) ============ */
|
||||
function MobileShell() {
|
||||
const { platform } = useStore();
|
||||
return (
|
||||
<div className={`absolute inset-0 flex flex-col bg-canvas plat-${platform}`}
|
||||
style={{ "--sat": "max(env(safe-area-inset-top), 12px)", "--sab": "max(env(safe-area-inset-bottom), 16px)" } as React.CSSProperties}>
|
||||
<div className="absolute inset-0 flex flex-col bg-canvas plat-android"
|
||||
style={{ "--sat": "max(env(safe-area-inset-top), 8px)", "--sab": "max(env(safe-area-inset-bottom), 6px)" } as React.CSSProperties}>
|
||||
<div className="relative flex-1 min-h-0">
|
||||
<AppBody />
|
||||
</div>
|
||||
|
||||
+198
-548
@@ -1,6 +1,5 @@
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { api, cover, fmt, fmtTime, isMobile } from "../api";
|
||||
import { api, cover, fmt, fmtTime, isMobile, mediaUrl } from "../api";
|
||||
import type { Detail, Episode, Post, VideoCard } from "../types";
|
||||
import { useStore } from "../store";
|
||||
import { Avatar, Img, Sheet } from "./ui";
|
||||
@@ -29,6 +28,10 @@ type Props = {
|
||||
startTime?: number;
|
||||
};
|
||||
|
||||
const RATES = [1, 1.25, 1.5, 2];
|
||||
|
||||
const stripHtml = (s: string) => s.replace(/<[^>]+>/g, " ").replace(/ /g, " ").replace(/\s+/g, " ").trim();
|
||||
|
||||
export default function Feed({ videoIds, startIndex = 0, title = "", mode, kind = "video", active, bottomInset, onBack, onNearEnd, startEp, startTime }: Props) {
|
||||
const store = useStore();
|
||||
const { isLiked, isFav, toggleLikeLocal, toggleFavLocal, toggleFollowLocal, muted, setMuted, volume, setVolume, toast, addHistory, user, setLoginOpen } = store;
|
||||
@@ -40,7 +43,7 @@ export default function Feed({ videoIds, startIndex = 0, title = "", mode, kind
|
||||
const [epMap, setEpMap] = useState<Record<number, number>>(() => (startEp ? { [videoIds[startIndex]]: startEp } : {}));
|
||||
const [details, setDetails] = useState<Record<number, Detail>>({});
|
||||
const [playUrls, setPlayUrls] = useState<Record<string, string>>({});
|
||||
const [cards] = useState<Record<number, VideoCard>>({});
|
||||
const [cards, setCards] = useState<Record<number, VideoCard>>({});
|
||||
const [posts, setPosts] = useState<Record<number, Post>>({});
|
||||
|
||||
const [time, setTime] = useState(0);
|
||||
@@ -65,22 +68,6 @@ export default function Feed({ videoIds, startIndex = 0, title = "", mode, kind
|
||||
const setTheater = store.setTheater;
|
||||
const fs = store.fs;
|
||||
const setFs = store.setFs;
|
||||
const clean = store.clean;
|
||||
const setClean = store.setClean;
|
||||
|
||||
/* 追踪手机视口是否已处于物理/系统横屏状态(window.innerWidth > window.innerHeight) */
|
||||
const [vpLandscape, setVpLandscape] = useState(
|
||||
() => typeof window !== "undefined" && window.innerWidth > window.innerHeight,
|
||||
);
|
||||
|
||||
/* 单击清屏 vs 双击暂停计时器 */
|
||||
const lastTapRef = useRef<{ time: number; timer: number | null }>({ time: 0, timer: null });
|
||||
const clearTapTimer = () => {
|
||||
if (lastTapRef.current.timer) {
|
||||
window.clearTimeout(lastTapRef.current.timer);
|
||||
lastTapRef.current.timer = null;
|
||||
}
|
||||
};
|
||||
|
||||
/* 桌面:鼠标闲置 2.8s 自动隐藏播放器 UI(沉浸) */
|
||||
const [idle, setIdle] = useState(false);
|
||||
@@ -100,7 +87,7 @@ export default function Feed({ videoIds, startIndex = 0, title = "", mode, kind
|
||||
}, [paused]);
|
||||
const [fullscreen, setFullscreen] = useState(false);
|
||||
const [heartBurst, setHeartBurst] = useState(0);
|
||||
/* —— 移动端手势 & 竖屏横片缩放 —— */
|
||||
/* —— 移动端手势 —— */
|
||||
const [holdSpeed, setHoldSpeed] = useState(false);
|
||||
const [speedLock, setSpeedLock] = useState(false);
|
||||
const [lockArmed, setLockArmed] = useState(false);
|
||||
@@ -108,17 +95,12 @@ export default function Feed({ videoIds, startIndex = 0, title = "", mode, kind
|
||||
const lockArmedRef = useRef(false);
|
||||
const [scrub, setScrub] = useState<{ pct: number; target: number } | null>(null);
|
||||
const scrubTarget = useRef<number | null>(null);
|
||||
/* 竖屏下横屏视频适应模式 + 双指无级缩放/平移 */
|
||||
const [portraitFit, setPortraitFit] = useState<"contain" | "cover">("contain");
|
||||
const [zoom, setZoom] = useState({ scale: 1, x: 0, y: 0, gesturing: false });
|
||||
const pinchRef = useRef<{
|
||||
dist0: number; midX0: number; midY0: number; scale0: number; x0: number; y0: number;
|
||||
} | null>(null);
|
||||
/* 进度条拖动 */
|
||||
const barRef = useRef<HTMLDivElement>(null);
|
||||
const barScrub = useRef(false);
|
||||
const [barPct, setBarPct] = useState<number | null>(null);
|
||||
const gesture = useRef<{
|
||||
x: number; y: number; startX: number; startY: number; t: number; timer: number | null;
|
||||
x: number; y: number; startY: number; t: number; timer: number | null;
|
||||
mode: "idle" | "hold" | "scrub" | "pan"; base: number; width: number; playing: boolean;
|
||||
} | null>(null);
|
||||
|
||||
@@ -131,12 +113,10 @@ export default function Feed({ videoIds, startIndex = 0, title = "", mode, kind
|
||||
const episodes = detail?.episodes || [];
|
||||
const post = posts[curId];
|
||||
|
||||
/* 观看进度:onTime 里每 5 秒落一次;拖动进度条期间忽略底层 timeupdate 防止进度条回跳 */
|
||||
/* 观看进度:onTime 里每 5 秒落一次;退出播放页时再用 liveRef 兜一次 */
|
||||
const onTimeTick = (t: number) => {
|
||||
liveRef.current = { id: curId, ep: curEp, dur: duration, t };
|
||||
if (!barScrub.current && gesture.current?.mode !== "scrub") {
|
||||
setTime(t);
|
||||
}
|
||||
setTime(t);
|
||||
const now = Date.now();
|
||||
if (duration > 0 && now - lastSaveRef.current > 5000) {
|
||||
lastSaveRef.current = now;
|
||||
@@ -199,122 +179,18 @@ export default function Feed({ videoIds, startIndex = 0, title = "", mode, kind
|
||||
const effRate = holdSpeed || speedLock ? 2 : rate;
|
||||
/* 进度条显示百分比(拖动时用拖动值) */
|
||||
const barProgress = barPct ?? (duration ? time / duration : 0);
|
||||
/* 是否为横屏视频(16:9 等宽大于高) */
|
||||
const isLandscapeVideo = vsize.w > vsize.h && vsize.h > 0;
|
||||
/* 仅当「全屏 + 横屏视频 + 手机系统视口尚未横过来 (!vpLandscape)」时才用 CSS 旋转 90° 兜底;
|
||||
一旦系统屏幕已经横过来了 (vpLandscape === true),不再叠加 CSS 旋转,彻底解决手机横置后视频反而竖过去的问题! */
|
||||
const rotated = !isDesktop && fs && isLandscapeVideo && !vpLandscape;
|
||||
/* 沉浸全屏 + 横屏视频 → 舞台旋转 90°,看起来就是横屏 */
|
||||
const rotated = !isDesktop && fs && vsize.w > vsize.h && vsize.h > 0;
|
||||
|
||||
/* 借鉴 stclock1988/hghub-ios (PlayerView.swift keepPlayingThroughTransition):
|
||||
iOS 在横竖屏几何旋转或全屏视图层级切换期间,系统底层 AVPlayer / WebKit 视频层可能被短暂挂起暂停。
|
||||
在过渡窗口期内分批重申 play(),确保旋转/全屏切换不中断播放。 */
|
||||
const keepPlayingTimers = useRef<number[]>([]);
|
||||
const keepPlayingThroughTransition = useCallback(() => {
|
||||
keepPlayingTimers.current.forEach((id) => window.clearTimeout(id));
|
||||
keepPlayingTimers.current = [];
|
||||
const el = videoRef.current?.el();
|
||||
const shouldPlay = el ? !el.paused : !paused;
|
||||
if (!shouldPlay) return;
|
||||
for (const delay of [50, 150, 300, 500, 800, 1200]) {
|
||||
const tid = window.setTimeout(() => {
|
||||
const v = videoRef.current?.el();
|
||||
if (v && v.paused && !v.ended) {
|
||||
videoRef.current?.play();
|
||||
}
|
||||
}, delay);
|
||||
keepPlayingTimers.current.push(tid);
|
||||
}
|
||||
}, [paused]);
|
||||
|
||||
useEffect(() => () => {
|
||||
keepPlayingTimers.current.forEach((id) => window.clearTimeout(id));
|
||||
}, []);
|
||||
|
||||
/* 监听手机屏幕横竖屏变化:物理横置手机时自动进入全屏,竖回时自动退出全屏 */
|
||||
useEffect(() => {
|
||||
if (isDesktop) return undefined;
|
||||
const onViewportChange = () => {
|
||||
const isLand = window.innerWidth > window.innerHeight;
|
||||
setVpLandscape((prev) => {
|
||||
if (prev !== isLand && active) {
|
||||
setFs(isLand);
|
||||
keepPlayingThroughTransition();
|
||||
}
|
||||
return isLand;
|
||||
});
|
||||
};
|
||||
window.addEventListener("resize", onViewportChange);
|
||||
window.addEventListener("orientationchange", onViewportChange);
|
||||
return () => {
|
||||
window.removeEventListener("resize", onViewportChange);
|
||||
window.removeEventListener("orientationchange", onViewportChange);
|
||||
};
|
||||
}, [isDesktop, active, setFs, keepPlayingThroughTransition]);
|
||||
|
||||
/* 进入 / 退出全屏:对横屏视频直接调用原生屏幕方向切换,让手机系统界面真正横过来 */
|
||||
const enterFs = useCallback(() => {
|
||||
keepPlayingThroughTransition();
|
||||
setClean(false);
|
||||
setFs(true);
|
||||
if (isLandscapeVideo) {
|
||||
invoke("set_orientation", { landscape: true }).catch(() => {});
|
||||
try {
|
||||
(screen.orientation as unknown as { lock?: (o: string) => Promise<void> })?.lock?.("landscape")?.catch(() => {});
|
||||
} catch { /* ignore */ }
|
||||
}
|
||||
}, [isLandscapeVideo, setClean, setFs, keepPlayingThroughTransition]);
|
||||
|
||||
const exitFs = useCallback(() => {
|
||||
keepPlayingThroughTransition();
|
||||
setClean(false);
|
||||
setFs(false);
|
||||
invoke("set_orientation", { landscape: false }).catch(() => {});
|
||||
try { screen.orientation?.unlock?.(); } catch { /* ignore */ }
|
||||
}, [setClean, setFs, keepPlayingThroughTransition]);
|
||||
|
||||
/* 全屏状态下若视频宽高刚加载出来且为横屏,自动补发一次横屏指令 */
|
||||
useEffect(() => {
|
||||
if (!isDesktop && fs && isLandscapeVideo) {
|
||||
invoke("set_orientation", { landscape: true }).catch(() => {});
|
||||
}
|
||||
}, [isDesktop, fs, isLandscapeVideo]);
|
||||
|
||||
/* 全屏切换或视口旋转后校准滚动容器 scrollTop:
|
||||
- 进入全屏时非当前项已隐藏,当前项位于顶部 scrollTop = 0;
|
||||
- 退出全屏回到竖屏列表时,立即将 scrollTop 重新对齐到 index * clientHeight,防止错位到其它视频封面。 */
|
||||
useEffect(() => {
|
||||
const el = boxRef.current;
|
||||
if (!el) return undefined;
|
||||
if (fs) {
|
||||
el.scrollTop = 0;
|
||||
return undefined;
|
||||
}
|
||||
const syncScroll = () => {
|
||||
const box = boxRef.current;
|
||||
if (!box || fs) return;
|
||||
box.scrollTop = index * (box.clientHeight || 1);
|
||||
};
|
||||
syncScroll();
|
||||
const raf = requestAnimationFrame(syncScroll);
|
||||
const t1 = window.setTimeout(syncScroll, 120);
|
||||
const t2 = window.setTimeout(syncScroll, 350);
|
||||
return () => {
|
||||
cancelAnimationFrame(raf);
|
||||
window.clearTimeout(t1);
|
||||
window.clearTimeout(t2);
|
||||
};
|
||||
}, [fs, vpLandscape, index]);
|
||||
|
||||
/* 滚动定位(全屏或缩放手势期间锁定索引,避免容器尺寸变化误触发翻页) */
|
||||
/* 滚动定位 */
|
||||
const onScroll = useCallback(() => {
|
||||
if (fs || pinchRef.current) return;
|
||||
const el = boxRef.current;
|
||||
if (!el) return;
|
||||
const h = el.clientHeight || 1;
|
||||
const i = Math.max(0, Math.min(videoIds.length - 1, Math.round(el.scrollTop / h)));
|
||||
setIndex((prev) => (prev === i ? prev : i));
|
||||
if (onNearEnd && i >= videoIds.length - 3) onNearEnd();
|
||||
}, [videoIds.length, onNearEnd, fs]);
|
||||
}, [videoIds.length, onNearEnd]);
|
||||
|
||||
const go = useCallback((delta: number) => {
|
||||
const el = boxRef.current;
|
||||
@@ -375,35 +251,20 @@ export default function Feed({ videoIds, startIndex = 0, title = "", mode, kind
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [curId, curEp]);
|
||||
|
||||
/* 切换条目/集数时重置播放与缩放状态 */
|
||||
/* 切换条目/集数时重置播放状态 */
|
||||
useEffect(() => {
|
||||
setTime(0); setDuration(0); setBuffered(0); setErr(""); setWaiting(true); setPaused(false); setDescOpen(false);
|
||||
setVsize({ w: 0, h: 0 });
|
||||
setPortraitFit("contain");
|
||||
setZoom({ scale: 1, x: 0, y: 0, gesturing: false });
|
||||
}, [playKey]);
|
||||
|
||||
/* 进出全屏时复位双指缩放并校准滚动条位置 */
|
||||
useEffect(() => {
|
||||
setZoom({ scale: 1, x: 0, y: 0, gesturing: false });
|
||||
if (!fs && boxRef.current) {
|
||||
const el = boxRef.current;
|
||||
requestAnimationFrame(() => {
|
||||
el.scrollTop = index * (el.clientHeight || 1);
|
||||
});
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [fs]);
|
||||
|
||||
/* 音量/静音同步 */
|
||||
useEffect(() => { videoRef.current?.mute(muted); }, [muted]);
|
||||
useEffect(() => { videoRef.current?.volume(volume); }, [volume]);
|
||||
/* 倍速同步(长按 2x / 锁定 2x / 基准倍速) */
|
||||
useEffect(() => { videoRef.current?.rate(effRate); }, [effRate, playKey]);
|
||||
|
||||
/* 离开播放页时把最后位置落盘并清理计时器 */
|
||||
/* 离开播放页时把最后位置落盘 */
|
||||
useEffect(() => () => {
|
||||
clearTapTimer();
|
||||
const s = liveRef.current;
|
||||
if (s.id && s.dur) addHistory(s.id, s.ep, s.t, s.dur);
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
@@ -457,91 +318,19 @@ export default function Feed({ videoIds, startIndex = 0, title = "", mode, kind
|
||||
else el.requestFullscreen().catch(() => {});
|
||||
};
|
||||
|
||||
/* —— 双指捏合缩放 & 平移(Pinch-to-Zoom & Pan) —— */
|
||||
const cancelSingleGesture = () => {
|
||||
clearTapTimer();
|
||||
const g = gesture.current;
|
||||
if (g?.timer) window.clearTimeout(g.timer);
|
||||
gesture.current = null;
|
||||
if (holdRef.current) {
|
||||
holdRef.current = false;
|
||||
setHoldSpeed(false);
|
||||
}
|
||||
lockArmedRef.current = false;
|
||||
setLockArmed(false);
|
||||
setScrub(null);
|
||||
scrubTarget.current = null;
|
||||
};
|
||||
|
||||
const onTouchStart = (e: React.TouchEvent<HTMLDivElement>) => {
|
||||
if (isDesktop || controlsLocked) return;
|
||||
if (e.touches.length === 2) {
|
||||
cancelSingleGesture();
|
||||
const t0 = e.touches[0];
|
||||
const t1 = e.touches[1];
|
||||
const dist0 = Math.max(12, Math.hypot(t1.clientX - t0.clientX, t1.clientY - t0.clientY));
|
||||
const midX0 = (t0.clientX + t1.clientX) / 2;
|
||||
const midY0 = (t0.clientY + t1.clientY) / 2;
|
||||
pinchRef.current = {
|
||||
dist0,
|
||||
midX0,
|
||||
midY0,
|
||||
scale0: zoom.scale,
|
||||
x0: zoom.x,
|
||||
y0: zoom.y,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
const onTouchMove = (e: React.TouchEvent<HTMLDivElement>) => {
|
||||
if (isDesktop || controlsLocked) return;
|
||||
if (e.touches.length === 2 && pinchRef.current) {
|
||||
const p = pinchRef.current;
|
||||
const t0 = e.touches[0];
|
||||
const t1 = e.touches[1];
|
||||
const dist = Math.max(12, Math.hypot(t1.clientX - t0.clientX, t1.clientY - t0.clientY));
|
||||
const midX = (t0.clientX + t1.clientX) / 2;
|
||||
const midY = (t0.clientY + t1.clientY) / 2;
|
||||
const nextScale = Math.max(0.85, Math.min(3.5, p.scale0 * (dist / p.dist0)));
|
||||
const rawDx = midX - p.midX0;
|
||||
const rawDy = midY - p.midY0;
|
||||
const dx = rotated ? rawDy : rawDx;
|
||||
const dy = rotated ? -rawDx : rawDy;
|
||||
const maxX = Math.max(0, (nextScale - 1) * window.innerWidth * 0.55);
|
||||
const maxY = Math.max(0, (nextScale - 1) * window.innerHeight * 0.55);
|
||||
const nextX = Math.max(-maxX, Math.min(maxX, p.x0 + dx));
|
||||
const nextY = Math.max(-maxY, Math.min(maxY, p.y0 + dy));
|
||||
setZoom({ scale: nextScale, x: nextX, y: nextY, gesturing: true });
|
||||
}
|
||||
};
|
||||
|
||||
const onTouchEnd = (e: React.TouchEvent<HTMLDivElement>) => {
|
||||
if (isDesktop) return;
|
||||
if (pinchRef.current && e.touches.length < 2) {
|
||||
pinchRef.current = null;
|
||||
setZoom((prev) =>
|
||||
prev.scale < 1.08
|
||||
? { scale: 1, x: 0, y: 0, gesturing: false }
|
||||
: { ...prev, gesturing: false },
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
/* —— 长按 2x(上滑锁定) / 横拖定位 / 单击清屏 / 双击暂停 —— */
|
||||
/* —— 长按 2x(上滑锁定) / 横拖定位 / 单击暂停 —— */
|
||||
const onDown = (e: React.PointerEvent<HTMLDivElement>) => {
|
||||
if (isDesktop || controlsLocked || !active || !e.isPrimary || pinchRef.current || gesture.current || e.button !== 0) return;
|
||||
if (isDesktop || controlsLocked || !active || gesture.current || e.button !== 0) return;
|
||||
const el = e.currentTarget;
|
||||
const span = rotated ? (el.clientHeight || window.innerHeight || 1) : (el.clientWidth || 1);
|
||||
const width = el.clientWidth || 1;
|
||||
try { el.setPointerCapture(e.pointerId); } catch { /* ignore */ }
|
||||
const g = {
|
||||
x: e.clientX, y: e.clientY, startX: e.clientX, startY: e.clientY,
|
||||
t: Date.now(), base: time, width: span,
|
||||
playing: videoRef.current?.el()?.paused === false,
|
||||
x: e.clientX, y: e.clientY, startY: e.clientY, t: Date.now(), base: time, width,
|
||||
mode: "idle" as "idle" | "hold" | "scrub" | "pan",
|
||||
playing: videoRef.current?.el()?.paused === false,
|
||||
timer: window.setTimeout(() => {
|
||||
const cur = gesture.current;
|
||||
if (!cur || cur.mode !== "idle" || pinchRef.current) return;
|
||||
clearTapTimer();
|
||||
if (!cur || cur.mode !== "idle") return;
|
||||
cur.mode = "hold";
|
||||
holdRef.current = true;
|
||||
setHoldSpeed(true);
|
||||
@@ -554,21 +343,14 @@ export default function Feed({ videoIds, startIndex = 0, title = "", mode, kind
|
||||
};
|
||||
|
||||
const onMove = (e: React.PointerEvent<HTMLDivElement>) => {
|
||||
if (pinchRef.current) {
|
||||
cancelSingleGesture();
|
||||
return;
|
||||
}
|
||||
const g = gesture.current;
|
||||
if (!g || isDesktop || !e.isPrimary) return;
|
||||
const rawDx = e.clientX - g.x;
|
||||
const rawDy = e.clientY - g.y;
|
||||
const dx = rotated ? rawDy : rawDx;
|
||||
const dy = rotated ? -rawDx : rawDy;
|
||||
if (!g || isDesktop) return;
|
||||
const dx = e.clientX - g.x;
|
||||
const dy = e.clientY - g.y;
|
||||
|
||||
/* 长按中:上滑 64px 进入「松开即锁定」 */
|
||||
if (g.mode === "hold") {
|
||||
const upDist = rotated ? (e.clientX - g.startX) : (g.startY - e.clientY);
|
||||
const armed = upDist > 64;
|
||||
const armed = g.startY - e.clientY > 64;
|
||||
if (armed !== lockArmedRef.current) {
|
||||
lockArmedRef.current = armed;
|
||||
setLockArmed(armed);
|
||||
@@ -577,12 +359,11 @@ export default function Feed({ videoIds, startIndex = 0, title = "", mode, kind
|
||||
}
|
||||
|
||||
if (g.mode === "idle") {
|
||||
if (Math.abs(dx) > 16 && Math.abs(dx) > Math.abs(dy) * 1.2) {
|
||||
clearTapTimer();
|
||||
if (Math.abs(dx) > 14 && Math.abs(dx) > Math.abs(dy)) {
|
||||
if (g.timer) window.clearTimeout(g.timer);
|
||||
g.mode = "scrub";
|
||||
} else if (Math.abs(dy) > 16) {
|
||||
clearTapTimer();
|
||||
videoRef.current?.pause();
|
||||
} else if (Math.abs(dy) > 14) {
|
||||
if (g.timer) window.clearTimeout(g.timer);
|
||||
g.mode = "pan";
|
||||
}
|
||||
@@ -592,14 +373,13 @@ export default function Feed({ videoIds, startIndex = 0, title = "", mode, kind
|
||||
if (g.mode === "scrub") {
|
||||
const total = duration || 0;
|
||||
if (!total) return;
|
||||
const target = Math.max(0, Math.min(total - 0.2, g.base + (dx / g.width) * total));
|
||||
const target = Math.max(0, Math.min(total, g.base + (dx / g.width) * total));
|
||||
scrubTarget.current = target;
|
||||
setScrub({ pct: (target / total) * 100, target });
|
||||
}
|
||||
};
|
||||
|
||||
const onUp = (e?: React.PointerEvent<HTMLDivElement>, cancelled = false) => {
|
||||
if (pinchRef.current) return;
|
||||
const onUp = (cancelled = false) => {
|
||||
const g = gesture.current;
|
||||
gesture.current = null;
|
||||
if (!g) return;
|
||||
@@ -618,40 +398,17 @@ export default function Feed({ videoIds, startIndex = 0, title = "", mode, kind
|
||||
}
|
||||
if (g.mode === "scrub") {
|
||||
const target = scrubTarget.current;
|
||||
if (!cancelled && target != null) videoRef.current?.seek(target, "mobile_gesture");
|
||||
setScrub(null);
|
||||
scrubTarget.current = null;
|
||||
if (!cancelled && target != null) {
|
||||
setErr("");
|
||||
setTime(target);
|
||||
videoRef.current?.seek(target, "mobile_gesture");
|
||||
}
|
||||
if (g.playing && active) videoRef.current?.play();
|
||||
return;
|
||||
}
|
||||
|
||||
if (cancelled || g.mode !== "idle") return;
|
||||
const moveDist = e ? Math.hypot(e.clientX - g.x, e.clientY - g.y) : 0;
|
||||
if (Date.now() - g.t < 260 && moveDist < 16) {
|
||||
const now = Date.now();
|
||||
if (now - lastTapRef.current.time < 280) {
|
||||
// 双击屏幕:切换暂停 / 播放
|
||||
clearTapTimer();
|
||||
lastTapRef.current.time = 0;
|
||||
videoRef.current?.toggle();
|
||||
} else {
|
||||
// 单击屏幕:切换清屏模式(消除或恢复所有界面控件,只显示视频内容)
|
||||
lastTapRef.current.time = now;
|
||||
clearTapTimer();
|
||||
lastTapRef.current.timer = window.setTimeout(() => {
|
||||
lastTapRef.current.timer = null;
|
||||
setClean((c) => !c);
|
||||
}, 250) as unknown as number;
|
||||
}
|
||||
}
|
||||
if (!cancelled && g.mode === "idle" && Date.now() - g.t < 260) videoRef.current?.toggle();
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (!active || controlsLocked) onUp(undefined, true);
|
||||
if (!active || controlsLocked) onUp(true);
|
||||
// Cancel pending gestures when the page is hidden or controls are locked.
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [active, controlsLocked]);
|
||||
@@ -663,32 +420,28 @@ export default function Feed({ videoIds, startIndex = 0, title = "", mode, kind
|
||||
|
||||
const lockControls = () => { setPanel(null); setControlsLocked(true); };
|
||||
|
||||
/* 长按倍速 / 双指缩放 / 全屏期间禁止外层列表原生滚动 */
|
||||
/* 长按倍速期间禁止原生滚动,否则上滑会被列表吃掉、锁不住倍速 */
|
||||
useEffect(() => {
|
||||
if (isDesktop) return undefined;
|
||||
const el = boxRef.current;
|
||||
if (!el) return undefined;
|
||||
const fn = (e: TouchEvent) => {
|
||||
if (holdRef.current || pinchRef.current || fs || e.touches.length >= 2) {
|
||||
e.preventDefault();
|
||||
}
|
||||
};
|
||||
const fn = (e: TouchEvent) => { if (holdRef.current) e.preventDefault(); };
|
||||
el.addEventListener("touchmove", fn, { passive: false });
|
||||
return () => el.removeEventListener("touchmove", fn);
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [isDesktop, videoIds.length, fs]);
|
||||
}, [isDesktop, videoIds.length]);
|
||||
|
||||
/* —— 进度条拖动(直接用当前触发元素的 BoundingRect,旋转舞台下按 Y 轴换算) —— */
|
||||
const barPctAt = (barEl: HTMLElement | null, clientX: number, clientY: number) => {
|
||||
const r = barEl?.getBoundingClientRect();
|
||||
/* —— 进度条拖动(旋转舞台下按 Y 轴换算) —— */
|
||||
const barPctAt = (clientX: number, clientY: number) => {
|
||||
const r = barRef.current?.getBoundingClientRect();
|
||||
if (!r) return null;
|
||||
const span = rotated ? r.height : r.width;
|
||||
if (!span) return null;
|
||||
const raw = rotated ? (clientY - r.top) / span : (clientX - r.left) / span;
|
||||
return Math.max(0, Math.min(1, raw));
|
||||
};
|
||||
const barSeekTo = (barEl: HTMLElement | null, clientX: number, clientY: number) => {
|
||||
const pct = barPctAt(barEl, clientX, clientY);
|
||||
const barSeekTo = (clientX: number, clientY: number) => {
|
||||
const pct = barPctAt(clientX, clientY);
|
||||
if (pct == null) return null;
|
||||
setBarPct(pct);
|
||||
return pct;
|
||||
@@ -697,29 +450,27 @@ export default function Feed({ videoIds, startIndex = 0, title = "", mode, kind
|
||||
e.stopPropagation();
|
||||
videoRef.current?.trace("seek.input.down", { input: "mobile_bar" });
|
||||
barScrub.current = true;
|
||||
const el = e.currentTarget as HTMLElement;
|
||||
try { el.setPointerCapture(e.pointerId); } catch { /* ignore */ }
|
||||
barSeekTo(el, e.clientX, e.clientY);
|
||||
try { (e.currentTarget as HTMLElement).setPointerCapture(e.pointerId); } catch { /* ignore */ }
|
||||
barSeekTo(e.clientX, e.clientY);
|
||||
};
|
||||
const onBarMove = (e: React.PointerEvent<HTMLDivElement>) => {
|
||||
if (!barScrub.current) return;
|
||||
e.stopPropagation();
|
||||
videoRef.current?.trace("seek.input.move", { input: "mobile_bar" });
|
||||
barSeekTo(e.currentTarget as HTMLElement, e.clientX, e.clientY);
|
||||
barSeekTo(e.clientX, e.clientY);
|
||||
};
|
||||
const onBarUp = (e: React.PointerEvent<HTMLDivElement>) => {
|
||||
if (!barScrub.current) return;
|
||||
barScrub.current = false;
|
||||
e.stopPropagation();
|
||||
const pct = barPctAt(e.currentTarget as HTMLElement, e.clientX, e.clientY) ?? barPct;
|
||||
setBarPct(null);
|
||||
if (pct != null && duration > 0) {
|
||||
const target = Math.max(0, Math.min(duration - 0.15, pct * duration));
|
||||
setErr("");
|
||||
setTime(target);
|
||||
const pct = barPctAt(e.clientX, e.clientY);
|
||||
if (pct != null && duration) {
|
||||
const target = pct * duration;
|
||||
videoRef.current?.trace("seek.input.up", { input: "mobile_bar", target });
|
||||
videoRef.current?.seek(target, "mobile_bar");
|
||||
setTime(target);
|
||||
}
|
||||
setBarPct(null);
|
||||
};
|
||||
|
||||
const togglePip = async () => {
|
||||
@@ -770,194 +521,43 @@ export default function Feed({ videoIds, startIndex = 0, title = "", mode, kind
|
||||
return <div className="absolute inset-0 bg-black flex items-center justify-center"><div className="w-9 h-9 spinner" /></div>;
|
||||
}
|
||||
|
||||
const effectiveFit: "contain" | "cover" = isDesktop
|
||||
? "contain"
|
||||
: isLandscapeVideo
|
||||
? (fs || vpLandscape ? "contain" : portraitFit)
|
||||
: (vpLandscape ? "contain" : "cover");
|
||||
|
||||
return (
|
||||
<div
|
||||
className={`hg-player-ui absolute inset-0 overflow-hidden bg-black player-root ${controlsLocked ? "is-locked" : ""} ${isDesktop ? "player-surface" : ""} ${theater ? "is-theater" : ""} ${isDesktop && idle ? "is-idle" : ""}`}
|
||||
className={`hg-player-ui absolute inset-0 overflow-hidden bg-black player-root ${controlsLocked ? "is-locked" : ""} ${isDesktop ? "player-surface" : ""} ${theater ? "is-theater" : ""} ${rotated ? "fs-landscape" : ""} ${isDesktop && idle ? "is-idle" : ""}`}
|
||||
onPointerMove={() => { if (isDesktop) wake(); }}>
|
||||
<div className="absolute inset-0" inert={controlsLocked}>
|
||||
{/* 氛围背景(全屏时隐藏,避免透出封面底图) */}
|
||||
{!fs && (
|
||||
<div className="absolute inset-0 scale-110 blur-3xl opacity-25 pointer-events-none">
|
||||
{posterUrl && <img src={posterUrl} alt="" className="w-full h-full object-cover" />}
|
||||
</div>
|
||||
)}
|
||||
{/* 氛围背景 */}
|
||||
<div className="absolute inset-0 scale-110 blur-3xl opacity-25 pointer-events-none">
|
||||
{posterUrl && <img src={posterUrl} alt="" className="w-full h-full object-cover" />}
|
||||
</div>
|
||||
|
||||
<div ref={boxRef} onScroll={onScroll}
|
||||
className={`absolute inset-y-0 left-0 no-bar ${fs ? "overflow-hidden" : "overflow-y-scroll snap-y snap-mandatory overscroll-y-contain"}`}
|
||||
className="absolute inset-y-0 left-0 overflow-y-scroll no-bar snap-y snap-mandatory overscroll-y-contain"
|
||||
style={{ right: isDesktop && panel ? 372 : 0, transition: "right .3s cubic-bezier(.2,0,0,1)" }}>
|
||||
{videoIds.map((vid, i) => {
|
||||
const isActive = i === index;
|
||||
return (
|
||||
<section
|
||||
key={vid}
|
||||
style={!isActive && fs ? { display: "none" } : undefined}
|
||||
className={`relative w-full h-full snap-start snap-always ${fs && isActive ? "" : "overflow-hidden"}`}>
|
||||
<section key={vid} className="relative w-full h-full snap-start snap-always overflow-hidden">
|
||||
{isActive && playUrl ? (
|
||||
<div className={rotated ? "fs-landscape" : (!isDesktop && fs ? "fs-immersive" : "absolute inset-0")}>
|
||||
<div
|
||||
className="absolute inset-0 overflow-hidden"
|
||||
style={{ touchAction: fs || zoom.scale > 1.05 ? "none" : "pan-y" }}
|
||||
onTouchStart={onTouchStart}
|
||||
onTouchMove={onTouchMove}
|
||||
onTouchEnd={onTouchEnd}
|
||||
onTouchCancel={onTouchEnd}
|
||||
onPointerDown={onDown}
|
||||
onPointerMove={onMove}
|
||||
onPointerUp={(e) => onUp(e, false)}
|
||||
onPointerCancel={(e) => onUp(e, true)}
|
||||
onLostPointerCapture={(e) => onUp(e, true)}>
|
||||
<VideoSurface
|
||||
ref={videoRef}
|
||||
src={playUrl}
|
||||
poster={fs ? undefined : posterUrl}
|
||||
autoPlay
|
||||
active={active}
|
||||
diagnosticContext={{ active, view: mode, kind, video_id: curId, episode: curEp }}
|
||||
muted={muted}
|
||||
volume={volume}
|
||||
rate={effRate}
|
||||
fit={effectiveFit}
|
||||
scale={zoom.scale}
|
||||
panX={zoom.x}
|
||||
panY={zoom.y}
|
||||
isGesturing={zoom.gesturing}
|
||||
onClick={() => { if (isDesktop) videoRef.current?.toggle(); }}
|
||||
onTime={onTimeTick}
|
||||
onDuration={onDurationTick}
|
||||
onSize={(w, h) => setVsize({ w, h })}
|
||||
onPlaying={() => { setPaused(false); setWaiting(false); setErr(""); }}
|
||||
onPause={() => setPaused(true)}
|
||||
onWaiting={() => setWaiting(true)}
|
||||
onEnded={() => { const next = episodes.find((e) => e.ep_num === curEp + 1); if (next) pickEp(next.ep_num); }}
|
||||
onError={(m) => setErr(m)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* 横拖定位浮层 */}
|
||||
{!isDesktop && scrub && (
|
||||
<div className="absolute inset-0 z-30 flex flex-col items-center justify-center pointer-events-none" style={{ background: "rgba(0,0,0,.25)" }}>
|
||||
<span className="text-[26px] font-bold hg-ink tabular-nums hg-ov-shadow">{fmtTime(scrub.target)}</span>
|
||||
<span className="text-[11px] hg-ink-4 mt-1 tabular-nums">/ {fmtTime(duration)}</span>
|
||||
<div className="mt-4 w-[62%] h-[3px] rounded-full overflow-hidden" style={{ background: "rgba(255,255,255,.25)" }}>
|
||||
<div className="h-full bg-white" style={{ width: `${scrub.pct}%` }} />
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 暂停 / 缓冲 / 报错恢复 */}
|
||||
{paused && !err && (
|
||||
<div className="absolute inset-0 z-10 flex items-center justify-center pointer-events-none">
|
||||
<span className="w-[66px] h-[66px] rounded-full flex items-center justify-center backdrop-blur-md"
|
||||
style={{ background: "rgba(0,0,0,.55)", boxShadow: "inset 0 0 0 1px rgba(255,255,255,.12)" }}>
|
||||
<IPlayF size={28} className="hg-ink ml-0.5" />
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
{waiting && !err && !paused && (
|
||||
<div className="absolute inset-0 z-10 flex items-center justify-center pointer-events-none"><div className="w-9 h-9 spinner" /></div>
|
||||
)}
|
||||
{err && (
|
||||
<div className="absolute inset-0 z-30 flex items-center justify-center">
|
||||
<div className="rounded-xl p-5 flex flex-col items-center gap-3 text-[13px] hg-ink-2" style={{ background: "rgba(0,0,0,.74)" }}>
|
||||
<span>视频暂时无法加载</span>
|
||||
<span className="text-[10.5px] hg-ink-4 max-w-[240px] text-center break-all">{err}</span>
|
||||
<button className="px-4 py-1.5 rounded-full hg-chip-strong hg-link text-[12.5px] font-semibold pressable"
|
||||
onClick={() => { setErr(""); setWaiting(true); videoRef.current?.reload(); }}>
|
||||
重新加载
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 移动端:倍速状态 / 锁定提示 */}
|
||||
{!isDesktop && (!clean || holdSpeed) && (holdSpeed || speedLock || rate !== 1) && (
|
||||
<button
|
||||
onClick={() => {
|
||||
if (speedLock) { setSpeedLock(false); toast("已解除倍速锁定", "info"); }
|
||||
else if (rate !== 1 && !holdSpeed) setRate(1);
|
||||
}}
|
||||
className={`absolute left-1/2 -translate-x-1/2 z-30 flex items-center gap-1.5 px-3.5 h-8 rounded-full backdrop-blur-md text-[12px] font-bold elev-2 pressable ${speedLock ? "bg-primary text-on-primary" : "hg-chip hg-gold"}`}
|
||||
style={{ top: rotated || vpLandscape ? 14 : "calc(var(--sat, 0px) + 54px)" }}>
|
||||
<IBoltF size={13} />
|
||||
{effRate}x {speedLock ? "已锁定 · 点按解除" : holdSpeed ? "倍速中 · 松开恢复" : "倍速"}
|
||||
</button>
|
||||
)}
|
||||
{!isDesktop && holdSpeed && (
|
||||
<div
|
||||
className={`absolute left-1/2 -translate-x-1/2 z-30 flex items-center gap-2 px-4 h-10 rounded-xl backdrop-blur-md elev-2 transition-all duration-200 ${lockArmed ? "bg-primary text-on-primary scale-110" : "hg-chip-strong hg-ink-2"}`}
|
||||
style={{ top: "38%" }}>
|
||||
<ILockF size={16} />
|
||||
<span className="text-[12.5px] font-bold">{lockArmed ? "松开锁定 2.0x" : "上滑到此锁定倍速"}</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 移动端:沉浸全屏控制栏(清屏 clean 模式下隐藏,单击屏幕可呼出/隐藏) */}
|
||||
{!isDesktop && fs && !clean && !controlsLocked && (
|
||||
<>
|
||||
<div className="absolute right-4 z-40 flex items-center gap-2"
|
||||
style={{ top: rotated || vpLandscape ? 14 : "calc(var(--sat, 0px) + 8px)" }}>
|
||||
<button onClick={lockControls} aria-label="锁定播放控制" title="锁定播放控制" aria-pressed={false}
|
||||
className="hg-chip-strong w-9 h-9 rounded-full backdrop-blur-md flex items-center justify-center pressable elev-1">
|
||||
<ILockF size={17} />
|
||||
</button>
|
||||
<button onClick={exitFs} aria-label="退出全屏"
|
||||
className="hg-chip-strong w-9 h-9 rounded-full backdrop-blur-md flex items-center justify-center pressable elev-1">
|
||||
<ICompress size={18} />
|
||||
</button>
|
||||
</div>
|
||||
{zoom.scale > 1.05 && (
|
||||
<button
|
||||
onClick={() => setZoom({ scale: 1, x: 0, y: 0, gesturing: false })}
|
||||
className="hg-chip-strong absolute left-4 z-40 px-3 h-8 rounded-full backdrop-blur-md text-[11.5px] font-semibold flex items-center gap-1 pressable elev-1"
|
||||
style={{ top: rotated || vpLandscape ? 14 : "calc(var(--sat, 0px) + 8px)" }}>
|
||||
还原画面 ({zoom.scale.toFixed(1)}x)
|
||||
</button>
|
||||
)}
|
||||
<div className="absolute inset-x-0 z-30 px-4" style={{ bottom: rotated || vpLandscape ? 46 : "calc(var(--sab, 0px) + 52px)", height: 26 }}>
|
||||
<div className="relative h-full" style={{ touchAction: "none" }}
|
||||
onPointerDown={onBarDown} onPointerMove={onBarMove} onPointerUp={onBarUp} onPointerCancel={onBarUp}>
|
||||
<div className={`absolute inset-x-0 bottom-[10px] rounded-full transition-all ${barPct !== null ? "h-[5px]" : "h-[3px]"}`}
|
||||
style={{ background: "rgba(255,255,255,.3)" }}>
|
||||
<div className="h-full rounded-full bg-white" style={{ width: `${barProgress * 100}%` }} />
|
||||
</div>
|
||||
{barPct !== null && (
|
||||
<div className="absolute left-1/2 -translate-x-1/2 -top-8 px-2.5 py-1 rounded-md hg-chip-strong backdrop-blur-md text-[12px] font-bold tabular-nums whitespace-nowrap">
|
||||
{fmtTime(barPct * (duration || 0))} / {fmtTime(duration)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="absolute inset-x-0 z-40 flex items-center gap-3 px-4"
|
||||
style={{ bottom: rotated || vpLandscape ? 10 : "calc(var(--sab, 0px) + 10px)" }}>
|
||||
<button onClick={() => videoRef.current?.toggle()}
|
||||
className="hg-chip shrink-0 w-9 h-9 rounded-full flex items-center justify-center pressable">
|
||||
{paused ? <IPlayF size={18} /> : <IPauseF size={17} />}
|
||||
</button>
|
||||
<span className="shrink-0 text-[11.5px] font-semibold hg-ink-2 tabular-nums">{fmtTime(time)}</span>
|
||||
<button
|
||||
onClick={() => {
|
||||
if (speedLock) { setSpeedLock(false); return; }
|
||||
const seq = [1, 1.25, 1.5, 2];
|
||||
const idx = seq.indexOf(rate);
|
||||
setRate(seq[(idx + 1) % seq.length]);
|
||||
}}
|
||||
className={`ml-auto shrink-0 flex items-center gap-1 px-2.5 h-8 rounded-full text-[12px] font-bold pressable ${effRate !== 1 ? "bg-primary text-on-primary" : "hg-chip hg-ink-2"}`}>
|
||||
<IBoltF size={12} />{effRate}x
|
||||
</button>
|
||||
<span className="shrink-0 text-[11.5px] hg-ink-4 tabular-nums">{fmtTime(duration)}</span>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
<div className="absolute inset-0" style={{ touchAction: "pan-y" }}
|
||||
onPointerDown={onDown} onPointerMove={onMove} onPointerUp={() => onUp()} onPointerCancel={() => onUp(true)} onLostPointerCapture={() => onUp(true)}>
|
||||
<VideoSurface ref={videoRef} src={playUrl} poster={posterUrl} autoPlay active={active} muted={muted}
|
||||
diagnosticContext={{ active, view: mode, kind, video_id: curId, episode: curEp }}
|
||||
volume={volume} rate={effRate}
|
||||
fit={isDesktop || (vsize.w > 0 && vsize.w > vsize.h) ? "contain" : "cover"}
|
||||
onClick={() => { if (isDesktop) videoRef.current?.toggle(); }}
|
||||
onTime={onTimeTick}
|
||||
onDuration={onDurationTick}
|
||||
onSize={(w, h) => setVsize({ w, h })}
|
||||
onPlaying={() => { setPaused(false); setWaiting(false); }}
|
||||
onPause={() => setPaused(true)}
|
||||
onWaiting={() => setWaiting(true)}
|
||||
onEnded={() => { const next = episodes.find((e) => e.ep_num === curEp + 1); if (next) pickEp(next.ep_num); }}
|
||||
onError={(m) => setErr(m)} />
|
||||
</div>
|
||||
) : (
|
||||
<div className="absolute inset-0">
|
||||
<Img src={cards[vid]?.cover || posts[vid]?.cover || details[vid]?.cover || (isActive ? detail?.cover : "") || ""} eager={Math.abs(i - index) <= 1} />
|
||||
<Img src={detail?.cover || cards[vid]?.cover || posts[vid]?.cover || ""} eager={Math.abs(i - index) <= 1} />
|
||||
<div className="absolute inset-0" style={{ background: "rgba(0,0,0,.25)" }} />
|
||||
</div>
|
||||
)}
|
||||
@@ -973,57 +573,12 @@ export default function Feed({ videoIds, startIndex = 0, title = "", mode, kind
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 渐变压暗,保证文字可读(清屏模式下不加压暗遮罩,只显示纯视频内容) */}
|
||||
{!fs && !clean && (
|
||||
<div className="absolute inset-0 pointer-events-none"
|
||||
style={{ background: "linear-gradient(0deg, rgba(8,11,15,.86) 0, rgba(11,14,20,.18) 26%, transparent 48%)" }} />
|
||||
)}
|
||||
|
||||
{/* 竖屏下观看横屏视频:快捷「放大铺满 / 完整显示 / 全屏横屏」与双指缩放复位胶囊 */}
|
||||
{isActive && !fs && !clean && !isDesktop && (isLandscapeVideo || zoom.scale > 1.05) && (
|
||||
<div
|
||||
className="absolute left-1/2 -translate-x-1/2 z-20 flex items-center gap-2"
|
||||
style={{ top: "64%" }}>
|
||||
{isLandscapeVideo && (
|
||||
<>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
if (zoom.scale > 1.05) {
|
||||
setZoom({ scale: 1, x: 0, y: 0, gesturing: false });
|
||||
setPortraitFit("contain");
|
||||
} else {
|
||||
setPortraitFit((f) => (f === "contain" ? "cover" : "contain"));
|
||||
}
|
||||
}}
|
||||
className="hg-chip-strong backdrop-blur-md px-3 h-7 rounded-full text-[11.5px] font-semibold flex items-center gap-1.5 pressable elev-1">
|
||||
{zoom.scale > 1.05
|
||||
? `还原缩放 (${zoom.scale.toFixed(1)}x)`
|
||||
: portraitFit === "contain"
|
||||
? "放大铺满"
|
||||
: "完整适应"}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={enterFs}
|
||||
className="hg-chip-strong backdrop-blur-md px-3 h-7 rounded-full text-[11.5px] font-semibold flex items-center gap-1 pressable elev-1">
|
||||
<IExpand size={12} />横屏全屏
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
{!isLandscapeVideo && zoom.scale > 1.05 && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setZoom({ scale: 1, x: 0, y: 0, gesturing: false })}
|
||||
className="hg-chip-strong backdrop-blur-md px-3 h-7 rounded-full text-[11.5px] font-semibold flex items-center gap-1 pressable elev-1">
|
||||
还原画面 ({zoom.scale.toFixed(1)}x)
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
{/* 渐变压暗,保证文字可读 */}
|
||||
<div className="absolute inset-0 pointer-events-none"
|
||||
style={{ background: "linear-gradient(0deg, rgba(8,11,15,.86) 0, rgba(11,14,20,.18) 26%, transparent 48%)" }} />
|
||||
|
||||
{/* 顶部 */}
|
||||
{!fs && !clean && mode === "context" ? (
|
||||
{!fs && mode === "context" ? (
|
||||
isDesktop ? (
|
||||
<div className="desktop-context-header">
|
||||
<button onClick={onBack} aria-label="返回"><IBack size={17} /></button>
|
||||
@@ -1041,7 +596,7 @@ export default function Feed({ videoIds, startIndex = 0, title = "", mode, kind
|
||||
|
||||
{/* 右侧操作栏(移动端):收藏 / 评论 / 全屏 / 分享
|
||||
颜色写死不跟主题走:浅色主题下这些字必须仍是白色 */}
|
||||
{!fs && !clean && !isDesktop && (
|
||||
{!fs && !isDesktop && (
|
||||
<div className="absolute right-3 z-20 flex flex-col items-center gap-[16px]"
|
||||
style={{ bottom: `calc(var(--sab, 0px) + ${bottomInset + 92}px)` }}>
|
||||
<button onClick={onFav} className="flex flex-col items-center gap-1 pressable" aria-pressed={isFav(curId)} aria-label="收藏">
|
||||
@@ -1052,7 +607,7 @@ export default function Feed({ videoIds, startIndex = 0, title = "", mode, kind
|
||||
<ICommentF size={26} className="hg-ink hg-ov-shadow" />
|
||||
<span className="text-[10.5px] hg-ink-2 hg-ov-shadow">评论</span>
|
||||
</button>
|
||||
<button onClick={enterFs} className="flex flex-col items-center gap-1 pressable" aria-label="全屏">
|
||||
<button onClick={() => setFs(true)} className="flex flex-col items-center gap-1 pressable" aria-label="全屏">
|
||||
<IExpand size={26} className="hg-ink hg-ov-shadow" />
|
||||
<span className="text-[10.5px] hg-ink-2 hg-ov-shadow">全屏</span>
|
||||
</button>
|
||||
@@ -1137,32 +692,63 @@ export default function Feed({ videoIds, startIndex = 0, title = "", mode, kind
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 移动端:标题 + 详情标签 + 进度线(清屏 clean 模式下隐藏) */}
|
||||
{!fs && !clean && !isDesktop && (
|
||||
{/* 移动端:标题 + 详情标签 + 进度线(不加底色,只铺一层柔和压暗保证可读) */}
|
||||
{!fs && !isDesktop && (
|
||||
<div className="absolute inset-x-0 z-20" style={{ bottom: `calc(var(--sab, 0px) + ${bottomInset}px)` }}>
|
||||
<div className="absolute inset-x-0 bottom-0 h-[190px] pointer-events-none"
|
||||
style={{ background: "linear-gradient(0deg, rgba(0,0,0,.82) 0%, rgba(0,0,0,.42) 45%, transparent 100%)" }} />
|
||||
<p className="relative px-4 pb-2 text-[14px] font-semibold leading-snug hg-ink hg-ov-shadow clamp-2">{meta.title}</p>
|
||||
<div className="relative pt-1.5 pb-2">
|
||||
<div className="relative pt-1.5 pb-2.5">
|
||||
<button onClick={() => setPanel("detail")}
|
||||
className="px-4 flex items-center gap-0.5 text-[10.5px] font-medium hg-ink hg-ov-shadow pressable">
|
||||
详情 · 第 {curEp} 集<IChevR size={11} />
|
||||
</button>
|
||||
{isActive && (
|
||||
<div className="mx-4 mt-1.5 relative" style={{ height: 22, touchAction: "none" }}
|
||||
onPointerDown={onBarDown} onPointerMove={onBarMove} onPointerUp={onBarUp} onPointerCancel={onBarUp}>
|
||||
<div className={`absolute inset-x-0 top-1/2 -translate-y-1/2 rounded-full transition-all ${barPct !== null ? "h-[5px]" : "h-[2.5px]"}`}
|
||||
style={{ background: "rgba(255,255,255,.3)" }}>
|
||||
<div className="h-full rounded-full bg-white"
|
||||
style={{ width: `${barProgress * 100}%`, transition: barPct !== null ? "none" : "width .25s linear" }} />
|
||||
</div>
|
||||
{barPct !== null && (
|
||||
<div className="absolute left-1/2 -translate-x-1/2 -top-8 px-2.5 py-1 rounded-md hg-chip-strong backdrop-blur-md text-[12px] font-bold tabular-nums whitespace-nowrap">
|
||||
{fmtTime(barPct * (duration || 0))} / {fmtTime(duration)}
|
||||
</div>
|
||||
)}
|
||||
<div ref={barRef} className="mx-4 mt-2 relative" style={{ height: 14, touchAction: "none" }}
|
||||
onPointerDown={onBarDown} onPointerMove={onBarMove} onPointerUp={onBarUp} onPointerCancel={onBarUp}>
|
||||
<div className="absolute inset-x-0 top-1/2 -translate-y-1/2 h-[2.5px] rounded-full" style={{ background: "rgba(255,255,255,.3)" }}>
|
||||
<div className="h-full rounded-full bg-white"
|
||||
style={{ width: `${barProgress * 100}%`, transition: barPct !== null ? "none" : "width .25s linear" }} />
|
||||
</div>
|
||||
)}
|
||||
{barPct !== null && (
|
||||
<div className="absolute left-1/2 -translate-x-1/2 -top-8 px-2.5 py-1 rounded-md hg-chip-strong backdrop-blur-md text-[12px] font-bold tabular-nums whitespace-nowrap">
|
||||
{fmtTime(barPct * (duration || 0))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
|
||||
{/* 横拖定位浮层 */}
|
||||
{!isDesktop && scrub && (
|
||||
<div className="absolute inset-0 z-30 flex flex-col items-center justify-center pointer-events-none" style={{ background: "rgba(0,0,0,.25)" }}>
|
||||
<span className="text-[26px] font-bold hg-ink tabular-nums hg-ov-shadow">{fmtTime(scrub.target)}</span>
|
||||
<span className="text-[11px] hg-ink-4 mt-1 tabular-nums">/ {fmtTime(duration)}</span>
|
||||
<div className="mt-4 w-[62%] h-[3px] rounded-full overflow-hidden" style={{ background: "rgba(255,255,255,.25)" }}>
|
||||
<div className="h-full bg-white" style={{ width: `${scrub.pct}%` }} />
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 暂停 / 缓冲 */}
|
||||
{isActive && paused && !err && (
|
||||
<div className="absolute inset-0 z-10 flex items-center justify-center pointer-events-none">
|
||||
<span className="w-[66px] h-[66px] rounded-full flex items-center justify-center backdrop-blur-md"
|
||||
style={{ background: "rgba(0,0,0,.55)", boxShadow: "inset 0 0 0 1px rgba(255,255,255,.12)" }}>
|
||||
<IPlayF size={28} className="hg-ink ml-0.5" />
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
{isActive && waiting && !err && !paused && (
|
||||
<div className="absolute inset-0 z-10 flex items-center justify-center pointer-events-none"><div className="w-9 h-9 spinner" /></div>
|
||||
)}
|
||||
{isActive && err && (
|
||||
<div className="absolute inset-0 z-20 flex items-center justify-center">
|
||||
<div className="rounded-xl p-5 flex flex-col items-center gap-3 text-[13px] hg-ink-2" style={{ background: "rgba(0,0,0,.7)" }}>
|
||||
<span>视频暂时无法加载</span>
|
||||
<span className="text-[10.5px] hg-ink-4 max-w-[240px] text-center break-all">{err}</span>
|
||||
<button className="hg-link text-[12.5px]" onClick={() => { setErr(""); setWaiting(true); videoRef.current?.play(); }}>重试</button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
@@ -1199,6 +785,70 @@ export default function Feed({ videoIds, startIndex = 0, title = "", mode, kind
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* 移动端:倍速状态 / 锁定提示 */}
|
||||
{!isDesktop && (holdSpeed || speedLock || rate !== 1) && (
|
||||
<button
|
||||
onClick={() => {
|
||||
if (speedLock) { setSpeedLock(false); toast("已解除倍速锁定", "info"); }
|
||||
else if (rate !== 1 && !holdSpeed) setRate(1);
|
||||
}}
|
||||
className={`absolute left-1/2 -translate-x-1/2 z-30 flex items-center gap-1.5 px-3.5 h-8 rounded-full backdrop-blur-md text-[12px] font-bold elev-2 pressable ${speedLock ? "bg-primary text-on-primary" : "hg-chip hg-gold"}`}
|
||||
style={{ top: "calc(var(--sat, 0px) + 54px)" }}>
|
||||
<IBoltF size={13} />
|
||||
{effRate}x {speedLock ? "已锁定 · 点按解除" : holdSpeed ? "倍速中 · 松开恢复" : "倍速"}
|
||||
</button>
|
||||
)}
|
||||
{!isDesktop && holdSpeed && (
|
||||
<div
|
||||
className={`absolute left-1/2 -translate-x-1/2 z-30 flex items-center gap-2 px-4 h-10 rounded-xl backdrop-blur-md elev-2 transition-all duration-200 ${lockArmed ? "bg-primary text-on-primary scale-110" : "hg-chip-strong hg-ink-2"}`}
|
||||
style={{ top: "38%" }}>
|
||||
<ILockF size={16} />
|
||||
<span className="text-[12.5px] font-bold">{lockArmed ? "松开锁定 2.0x" : "上滑到此锁定倍速"}</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 移动端全屏模式下的进度条(普通模式的进度条在底部灰块里) */}
|
||||
{!isDesktop && fs && (
|
||||
<div className="absolute inset-x-0 z-30 px-4" style={{ bottom: "calc(var(--sab, 0px) + 52px)", height: 22 }}>
|
||||
<div ref={barRef} className="relative h-full" style={{ touchAction: "none" }}
|
||||
onPointerDown={onBarDown} onPointerMove={onBarMove} onPointerUp={onBarUp} onPointerCancel={onBarUp}>
|
||||
<div className="absolute inset-x-0 bottom-[8px] h-[2.5px] rounded-full" style={{ background: "rgba(255,255,255,.3)" }}>
|
||||
<div className="h-full rounded-full bg-white" style={{ width: `${barProgress * 100}%` }} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 移动端:沉浸全屏(安卓 WebView 不支持 Fullscreen API,改用应用内沉浸层) */}
|
||||
{!isDesktop && fs && (
|
||||
<>
|
||||
<button onClick={() => setFs(false)} aria-label="退出全屏"
|
||||
className="hg-chip-strong absolute right-3 z-40 w-9 h-9 rounded-full backdrop-blur-md flex items-center justify-center pressable elev-1"
|
||||
style={{ top: "calc(var(--sat, 0px) + 6px)" }}>
|
||||
<ICompress size={18} />
|
||||
</button>
|
||||
<div className="absolute inset-x-0 z-40 flex items-center gap-3 px-4"
|
||||
style={{ bottom: "calc(var(--sab, 0px) + 10px)" }}>
|
||||
<button onClick={() => videoRef.current?.toggle()}
|
||||
className="hg-chip shrink-0 w-9 h-9 rounded-full flex items-center justify-center pressable">
|
||||
{paused ? <IPlayF size={18} /> : <IPauseF size={17} />}
|
||||
</button>
|
||||
<span className="shrink-0 text-[11.5px] font-semibold hg-ink-2 tabular-nums">{fmtTime(time)}</span>
|
||||
<button
|
||||
onClick={() => {
|
||||
if (speedLock) { setSpeedLock(false); return; }
|
||||
const seq = [1, 1.25, 1.5, 2];
|
||||
const i = seq.indexOf(rate);
|
||||
setRate(seq[(i + 1) % seq.length]);
|
||||
}}
|
||||
className={`ml-auto shrink-0 flex items-center gap-1 px-2.5 h-8 rounded-full text-[12px] font-bold pressable ${effRate !== 1 ? "bg-primary text-on-primary" : "hg-chip hg-ink-2"}`}>
|
||||
<IBoltF size={12} />{effRate}x
|
||||
</button>
|
||||
<span className="shrink-0 text-[11.5px] hg-ink-4 tabular-nums">{fmtTime(duration)}</span>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* 选集 / 评论:桌面停靠在右侧(画面让位),移动端底部弹层 */}
|
||||
{isDesktop ? (
|
||||
<div className={`desktop-dock-panel ${panel ? "is-open" : ""}`}>
|
||||
@@ -1295,16 +945,16 @@ export default function Feed({ videoIds, startIndex = 0, title = "", mode, kind
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
{!isDesktop && !fs && !clean && !controlsLocked && active && (
|
||||
<div className="absolute right-3 z-40 flex items-center gap-2" style={{ top: "calc(var(--sat, 0px) + 6px)" }}>
|
||||
<button onClick={() => setMuted(m => !m)} aria-label={muted ? "取消静音" : "静音"}
|
||||
{!isDesktop && !controlsLocked && active && (
|
||||
<div className={`absolute z-40 flex items-center gap-2 ${fs ? "right-14" : "right-3"}`} style={{ top: "calc(var(--sat, 0px) + 6px)" }}>
|
||||
{!fs && <button onClick={() => setMuted(m => !m)} aria-label={muted ? "取消静音" : "静音"}
|
||||
className="hg-chip w-9 h-9 rounded-full flex items-center justify-center pressable elev-1">
|
||||
{muted ? <IVolMute size={17} /> : <IVol size={17} />}
|
||||
</button>
|
||||
</button>}
|
||||
<button onClick={lockControls} aria-label="锁定播放控制" title="锁定播放控制" aria-pressed={false}
|
||||
className="hg-chip w-9 h-9 rounded-full flex items-center justify-center pressable elev-1"><ILockF size={17} /></button>
|
||||
<button onClick={() => store.setTab("search")} aria-label="搜索"
|
||||
className="hg-chip w-9 h-9 rounded-full flex items-center justify-center pressable elev-1"><ISearch size={18} /></button>
|
||||
{!fs && <button onClick={() => store.setTab("search")} aria-label="搜索"
|
||||
className="hg-chip w-9 h-9 rounded-full flex items-center justify-center pressable elev-1"><ISearch size={18} /></button>}
|
||||
</div>
|
||||
)}
|
||||
{controlsLocked && <PlaybackLock active={active} onUnlock={() => { setControlsLocked(false); wake(); }} />}
|
||||
|
||||
+44
-269
@@ -1,6 +1,6 @@
|
||||
import React, { useEffect, useImperativeHandle, useRef, forwardRef, useState } from "react";
|
||||
import { useEffect, useImperativeHandle, useRef, forwardRef, useState } from "react";
|
||||
import Hls from "hls.js";
|
||||
import { isLocalMedia, platform, playlist } from "../api";
|
||||
import { isLocalMedia, playlist } from "../api";
|
||||
import { mediaResource, observeHls, usePlayerDiagnostics } from "../playbackDiagnostics";
|
||||
import { usePlaybackActivity } from "../usePlaybackActivity";
|
||||
|
||||
@@ -9,12 +9,11 @@ export type VideoHandle = {
|
||||
play: () => void;
|
||||
pause: () => void;
|
||||
toggle: () => void;
|
||||
seek: (t: number, sourceOrAutoResume?: string | boolean) => void;
|
||||
seek: (t: number, source?: string) => void;
|
||||
trace: (event: string, data?: Record<string, unknown>) => void;
|
||||
rate: (r: number) => void;
|
||||
mute: (m: boolean) => void;
|
||||
volume: (v: number) => void;
|
||||
reload: () => void;
|
||||
};
|
||||
|
||||
type Props = {
|
||||
@@ -26,11 +25,6 @@ type Props = {
|
||||
muted?: boolean;
|
||||
loop?: boolean;
|
||||
fit?: "contain" | "cover";
|
||||
/** 缩放倍率与平移偏移(用于移动端竖屏下双指缩放横屏视频) */
|
||||
scale?: number;
|
||||
panX?: number;
|
||||
panY?: number;
|
||||
isGesturing?: boolean;
|
||||
/** 换源后重新套用,避免切集时音量/倍速被浏览器重置 */
|
||||
volume?: number;
|
||||
rate?: number;
|
||||
@@ -48,75 +42,16 @@ type Props = {
|
||||
|
||||
/** 只负责「播」:hls.js + video 元素,控制条由外层渲染。 */
|
||||
const VideoSurface = forwardRef<VideoHandle, Props>(function VideoSurface(
|
||||
{ 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,
|
||||
{ src, poster, autoPlay = true, active = true, diagnosticContext = {}, muted = false, loop = false, fit = "contain", volume = 1, rate = 1,
|
||||
onTime, onDuration, onSize, onPlaying, onPause, onWaiting, onEnded, onError, onClick, className = "" },
|
||||
ref,
|
||||
) {
|
||||
const videoRef = useRef<HTMLVideoElement>(null);
|
||||
const hlsRef = useRef<Hls | null>(null);
|
||||
const recoverCountRef = useRef(0);
|
||||
const recoverTimerRef = useRef<number | null>(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) {
|
||||
onDuration?.(v.duration);
|
||||
}
|
||||
const w = v.videoWidth || 0;
|
||||
const h = v.videoHeight || 0;
|
||||
if (w > 0 && h > 0 && (w !== lastSizeRef.current.w || h !== lastSizeRef.current.h)) {
|
||||
lastSizeRef.current = { w, h };
|
||||
onSize?.(w, h);
|
||||
}
|
||||
};
|
||||
|
||||
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 {
|
||||
hlsRef.current.startLoad(target);
|
||||
} catch { /* ignore */ }
|
||||
}
|
||||
|
||||
try {
|
||||
v.currentTime = target;
|
||||
trace("seek.assigned", { target, source });
|
||||
} catch (e) {
|
||||
trace("seek.rejected", { error_name: (e as Error).name });
|
||||
}
|
||||
|
||||
if (autoResume && activity.isActive()) {
|
||||
const resumeOnce = () => {
|
||||
v.removeEventListener("seeked", resumeOnce);
|
||||
v.removeEventListener("canplay", resumeOnce);
|
||||
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 && activity.isActive()) {
|
||||
v.removeEventListener("seeked", resumeOnce);
|
||||
v.removeEventListener("canplay", resumeOnce);
|
||||
v.play().catch(() => {});
|
||||
}
|
||||
}, 350);
|
||||
}
|
||||
};
|
||||
|
||||
useImperativeHandle(ref, () => ({
|
||||
el: () => videoRef.current,
|
||||
play: () => activity.play("handle"),
|
||||
@@ -127,47 +62,29 @@ const VideoSurface = forwardRef<VideoHandle, Props>(function VideoSurface(
|
||||
trace("toggle.request");
|
||||
if (v.paused) activity.play("toggle"); else activity.pause("toggle");
|
||||
},
|
||||
seek: (t: number, sourceOrAutoResume: string | boolean = "handle") => safeSeek(t, sourceOrAutoResume),
|
||||
seek: (t: number, source = "handle") => {
|
||||
const v = videoRef.current;
|
||||
if (v && Number.isFinite(t)) {
|
||||
requestSeek(t, source);
|
||||
try { v.currentTime = t; trace("seek.assigned", { target: t, source }); }
|
||||
catch (e) { trace("seek.rejected", { error_name: (e as Error).name }); throw e; }
|
||||
}
|
||||
},
|
||||
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; },
|
||||
reload: () => {
|
||||
const v = videoRef.current;
|
||||
if (!v) return;
|
||||
recoverCountRef.current = 0;
|
||||
const cur = v.currentTime || 0;
|
||||
if (hlsRef.current) {
|
||||
try {
|
||||
hlsRef.current.startLoad(cur);
|
||||
activity.play("reload");
|
||||
return;
|
||||
} catch { /* ignore */ }
|
||||
}
|
||||
v.load();
|
||||
if (cur > 0) {
|
||||
try { v.currentTime = cur; } catch { /* ignore */ }
|
||||
}
|
||||
activity.play("reload");
|
||||
},
|
||||
}));
|
||||
}), []);
|
||||
|
||||
useEffect(() => {
|
||||
const video = videoRef.current;
|
||||
if (!video || !src) return;
|
||||
setReady(false);
|
||||
recoverCountRef.current = 0;
|
||||
lastSizeRef.current = { w: 0, h: 0 };
|
||||
if (recoverTimerRef.current) {
|
||||
window.clearTimeout(recoverTimerRef.current);
|
||||
recoverTimerRef.current = null;
|
||||
}
|
||||
if (hlsRef.current) { hlsRef.current.destroy(); hlsRef.current = null; }
|
||||
|
||||
const proxied = isLocalMedia(src);
|
||||
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 后浏览器会把它们重置成默认值 */
|
||||
@@ -186,27 +103,15 @@ const VideoSurface = forwardRef<VideoHandle, Props>(function VideoSurface(
|
||||
interstitialsController: undefined,
|
||||
contentSteeringController: undefined,
|
||||
enableInterstitialPlayback: false,
|
||||
// iOS WKWebView 下 WebWorker 跨自定义协议 hg:// 高频中断易死锁,关闭 Worker 走主线程加载更稳
|
||||
enableWorker: !isIos,
|
||||
enableWorker: true,
|
||||
// Prefer standard MSE on macOS; hls.js handles MMS-only fallback and seek recovery.
|
||||
preferManagedMediaSource: false,
|
||||
autoStartLoad: false,
|
||||
lowLatencyMode: false,
|
||||
maxBufferLength: 30,
|
||||
maxMaxBufferLength: 60,
|
||||
backBufferLength: 30,
|
||||
maxBufferHole: 0.5,
|
||||
highBufferWatchdogPeriod: 2,
|
||||
nudgeOffset: 0.25,
|
||||
nudgeMaxRetry: 6,
|
||||
manifestLoadingTimeOut: 20000,
|
||||
manifestLoadingMaxRetry: 4,
|
||||
levelLoadingTimeOut: 20000,
|
||||
levelLoadingMaxRetry: 4,
|
||||
fragLoadingTimeOut: 25000,
|
||||
fragLoadingMaxRetry: 6,
|
||||
fragLoadingRetryDelay: 400,
|
||||
startFragPrefetch: true,
|
||||
manifestLoadingMaxRetry: 3,
|
||||
fragLoadingMaxRetry: 4,
|
||||
});
|
||||
hlsRef.current = hls;
|
||||
observeHls(hls, trace);
|
||||
@@ -216,63 +121,13 @@ const VideoSurface = forwardRef<VideoHandle, Props>(function VideoSurface(
|
||||
if (activity.isActive()) hls.startLoad();
|
||||
if (autoPlay) activity.play("manifest_autoplay", true);
|
||||
});
|
||||
hls.on(Hls.Events.FRAG_BUFFERED, () => {
|
||||
recoverCountRef.current = 0;
|
||||
setReady(true);
|
||||
});
|
||||
hls.on(Hls.Events.ERROR, (_e, data) => {
|
||||
// 非致命卡顿错误(常见于拖动进度条后缓冲空洞):主动触发加载与微调跳帧
|
||||
if (!data.fatal) {
|
||||
if (
|
||||
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);
|
||||
} catch { /* ignore */ }
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!data.fatal) return;
|
||||
onError?.(`${data.type}/${data.details}`);
|
||||
if (!activity.isActive()) return;
|
||||
|
||||
// 致命错误:优先自动重连/恢复解码器,最多静默恢复 4 次,避免拖动进度条直接弹报错层
|
||||
if (data.type === Hls.ErrorTypes.NETWORK_ERROR) {
|
||||
if (recoverCountRef.current < 4) {
|
||||
recoverCountRef.current += 1;
|
||||
const delay = 250 * recoverCountRef.current;
|
||||
if (recoverTimerRef.current) window.clearTimeout(recoverTimerRef.current);
|
||||
recoverTimerRef.current = window.setTimeout(() => {
|
||||
if (!hlsRef.current || !activity.isActive()) return;
|
||||
try {
|
||||
hlsRef.current.startLoad(video.currentTime || -1);
|
||||
if (!video.paused) video.play().catch(() => {});
|
||||
} catch { /* ignore */ }
|
||||
}, delay);
|
||||
return;
|
||||
}
|
||||
onError?.(`${data.type}/${data.details}`);
|
||||
hls.startLoad();
|
||||
} else if (data.type === Hls.ErrorTypes.MEDIA_ERROR) {
|
||||
if (recoverCountRef.current < 4) {
|
||||
recoverCountRef.current += 1;
|
||||
try {
|
||||
if (recoverCountRef.current === 2) hls.swapAudioCodec();
|
||||
hls.recoverMediaError();
|
||||
video.play().catch(() => {});
|
||||
} catch { /* ignore */ }
|
||||
return;
|
||||
}
|
||||
onError?.(`${data.type}/${data.details}`);
|
||||
hls.recoverMediaError();
|
||||
} else {
|
||||
onError?.(`${data.type}/${data.details}`);
|
||||
hls.destroy();
|
||||
hlsRef.current = null;
|
||||
}
|
||||
if (data.type === Hls.ErrorTypes.NETWORK_ERROR) hls.startLoad();
|
||||
else if (data.type === Hls.ErrorTypes.MEDIA_ERROR) hls.recoverMediaError();
|
||||
else { hls.destroy(); hlsRef.current = null; }
|
||||
});
|
||||
} else {
|
||||
video.src = url;
|
||||
@@ -281,10 +136,6 @@ const VideoSurface = forwardRef<VideoHandle, Props>(function VideoSurface(
|
||||
|
||||
return () => {
|
||||
trace("source.cleanup");
|
||||
if (recoverTimerRef.current) {
|
||||
window.clearTimeout(recoverTimerRef.current);
|
||||
recoverTimerRef.current = null;
|
||||
}
|
||||
if (hlsRef.current) { hlsRef.current.destroy(); hlsRef.current = null; }
|
||||
};
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
@@ -300,106 +151,30 @@ const VideoSurface = forwardRef<VideoHandle, Props>(function VideoSurface(
|
||||
v.playbackRate = rate;
|
||||
};
|
||||
|
||||
const nearEndFiredRef = useRef(false);
|
||||
useEffect(() => {
|
||||
nearEndFiredRef.current = false;
|
||||
}, [src]);
|
||||
|
||||
// Native Resize Event listener for HTMLVideoElement (React doesn't always bind onResize on <video>)
|
||||
useEffect(() => {
|
||||
const v = videoRef.current;
|
||||
if (!v) return undefined;
|
||||
const onVideoResize = () => reportSizeAndDuration(v);
|
||||
v.addEventListener("resize", onVideoResize);
|
||||
return () => v.removeEventListener("resize", onVideoResize);
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [src]);
|
||||
|
||||
const hasTransform = scale !== 1 || panX !== 0 || panY !== 0;
|
||||
|
||||
return (
|
||||
<div className={`relative w-full h-full bg-black overflow-hidden ${className}`}>
|
||||
{!ready && poster && (
|
||||
<img
|
||||
src={poster}
|
||||
alt=""
|
||||
className={`absolute inset-0 w-full h-full pointer-events-none ${fit === "cover" ? "object-cover" : "object-contain"}`}
|
||||
/>
|
||||
)}
|
||||
<video
|
||||
ref={videoRef}
|
||||
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"}`}
|
||||
style={{
|
||||
opacity: ready ? 1 : 0,
|
||||
transform: hasTransform ? `translate3d(${panX}px, ${panY}px, 0) scale(${scale})` : "translateZ(0)",
|
||||
transformOrigin: "center center",
|
||||
transition: isGesturing ? "opacity .25s" : "opacity .25s, transform .2s cubic-bezier(.2,0,0,1)",
|
||||
}}
|
||||
onLoadedData={(e) => {
|
||||
const v = e.target as HTMLVideoElement;
|
||||
setReady(true);
|
||||
reapply(v);
|
||||
reportSizeAndDuration(v);
|
||||
}}
|
||||
onCanPlay={(e) => {
|
||||
const v = e.target as HTMLVideoElement;
|
||||
setReady(true);
|
||||
reportSizeAndDuration(v);
|
||||
}}
|
||||
onTimeUpdate={(e) => {
|
||||
const v = e.target as HTMLVideoElement;
|
||||
onTime?.(v.currentTime);
|
||||
if (lastSizeRef.current.w === 0 && v.videoWidth > 0) {
|
||||
reportSizeAndDuration(v);
|
||||
}
|
||||
// 借鉴 stclock1988/hghub-ios:部分 HLS 流容器标称时长比最后一个分片略长 0.5~1.2s,
|
||||
// 接近片尾时提前复位准备,若卡在片尾则自动触发连播
|
||||
if (!loop && !nearEndFiredRef.current && activity.isActive() && v.duration > 5 && v.currentTime >= v.duration - 0.35) {
|
||||
nearEndFiredRef.current = true;
|
||||
onEnded?.();
|
||||
}
|
||||
}}
|
||||
onLoadedMetadata={(e) => {
|
||||
const v = e.target as HTMLVideoElement;
|
||||
reapply(v);
|
||||
reportSizeAndDuration(v);
|
||||
}}
|
||||
onPlay={() => { if (activity.isActive()) onPlaying?.(); }}
|
||||
onPause={() => onPause?.()}
|
||||
onWaiting={(e) => {
|
||||
const v = e.target as HTMLVideoElement;
|
||||
if (!loop && !nearEndFiredRef.current && activity.isActive() && v.duration > 5 && v.currentTime >= v.duration - 1.5) {
|
||||
nearEndFiredRef.current = true;
|
||||
onEnded?.();
|
||||
return;
|
||||
}
|
||||
onWaiting?.();
|
||||
}}
|
||||
onPlaying={(e) => {
|
||||
setReady(true);
|
||||
recoverCountRef.current = 0;
|
||||
reportSizeAndDuration(e.target as HTMLVideoElement);
|
||||
if (activity.isActive()) onPlaying?.();
|
||||
}}
|
||||
onSeeking={() => onWaiting?.()}
|
||||
onSeeked={() => {
|
||||
const v = videoRef.current;
|
||||
if (v && !v.paused && activity.isActive()) onPlaying?.();
|
||||
}}
|
||||
onEnded={() => {
|
||||
if (!nearEndFiredRef.current && activity.isActive()) {
|
||||
nearEndFiredRef.current = true;
|
||||
onEnded?.();
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<video
|
||||
ref={videoRef}
|
||||
poster={poster}
|
||||
playsInline
|
||||
muted={muted}
|
||||
loop={loop}
|
||||
onClick={onClick}
|
||||
className={`w-full h-full bg-black ${fit === "cover" ? "object-cover" : "object-contain"} ${className}`}
|
||||
style={{ opacity: ready ? 1 : 0, transition: "opacity .35s" }}
|
||||
onLoadedData={(e) => { setReady(true); reapply(e.target as HTMLVideoElement); }}
|
||||
onTimeUpdate={(e) => onTime?.((e.target as HTMLVideoElement).currentTime)}
|
||||
onLoadedMetadata={(e) => {
|
||||
const v = e.target as HTMLVideoElement;
|
||||
reapply(v);
|
||||
onDuration?.(v.duration || 0);
|
||||
onSize?.(v.videoWidth || 0, v.videoHeight || 0);
|
||||
}}
|
||||
onPlay={() => { if (activity.isActive()) onPlaying?.(); }}
|
||||
onPause={() => onPause?.()}
|
||||
onWaiting={() => onWaiting?.()}
|
||||
onPlaying={() => { if (activity.isActive()) onPlaying?.(); }}
|
||||
onEnded={() => { if (activity.isActive()) onEnded?.(); }}
|
||||
/>
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
+4
-21
@@ -34,7 +34,6 @@
|
||||
}
|
||||
.plat-windows { --r-sm: 4px; --r-md: 8px; --r-lg: 8px; --r-ctl: 4px; --nav-h: 0px; }
|
||||
.plat-macos { --r-sm: 6px; --r-md: 10px; --r-lg: 12px; --r-ctl: 6px; --nav-h: 0px; }
|
||||
.plat-ios { --r-sm: 10px; --r-md: 14px; --r-lg: 18px; --r-ctl: 999px; -webkit-touch-callout: none; }
|
||||
html.theme-light {
|
||||
color-scheme: light;
|
||||
--p-canvas: #f3f3f3;
|
||||
@@ -153,7 +152,7 @@ html.theme-light .elev-3 { box-shadow: 0 10px 30px rgba(0,0,0,.1); }
|
||||
.a-panel-out { animation: kf-panel-out .2s ease-in both; }
|
||||
@keyframes kf-scale-in { from{opacity:0;transform:scale(.92)} to{opacity:1;transform:scale(1)} }
|
||||
.a-scale-in { animation: kf-scale-in .22s cubic-bezier(.2,0,0,1) both; }
|
||||
@keyframes kf-page-in { from{transform:translateX(100%)} to{transform:none} }
|
||||
@keyframes kf-page-in { from{transform:translateX(100%)} to{transform:translateX(0)} }
|
||||
.a-page-in { animation: kf-page-in .3s cubic-bezier(.2,0,0,1) both; }
|
||||
@keyframes kf-page-out { from{transform:translateX(0)} to{transform:translateX(100%)} }
|
||||
.a-page-out { animation: kf-page-out .22s cubic-bezier(.3,0,.8,.15) both; }
|
||||
@@ -251,8 +250,7 @@ input[type="range"].hg-range::-webkit-slider-thumb { -webkit-appearance: none; w
|
||||
原生全屏时红绿灯被系统隐藏(is-native-fs),让位收回,避免留一条空白。 */
|
||||
.plat-macos .win-titlebar { padding-left: 84px; }
|
||||
.plat-macos .win-titlebar.is-native-fs { padding-left: 14px; }
|
||||
.plat-android .win-main,
|
||||
.plat-ios .win-main { background: var(--p-bg); overflow: hidden; }
|
||||
.plat-android .win-main { background: var(--p-bg); overflow: hidden; }
|
||||
.win-page-in { animation: kf-page-in .26s cubic-bezier(.2,0,0,1) both; }
|
||||
.win-page-out { animation: kf-page-out .2s ease-in both; }
|
||||
|
||||
@@ -485,28 +483,13 @@ input[type="range"].hg-range::-webkit-slider-thumb { -webkit-appearance: none; w
|
||||
.player-surface .player-root,
|
||||
.player-root { background: #15181d; }
|
||||
|
||||
/* —— 移动端沉浸全屏:固定铺满全屏视口,脱离外层滚动容器 scrollTop 影响 —— */
|
||||
.fs-immersive {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
width: 100vw; height: 100vh;
|
||||
width: 100dvw; height: 100dvh;
|
||||
z-index: 45;
|
||||
background: #000;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* —— 移动端沉浸全屏(系统仍处于竖屏时的 CSS 90° 旋转兜底) —— */
|
||||
/* —— 安卓沉浸全屏:横屏视频把舞台旋转 90°(不依赖系统旋转) —— */
|
||||
.fs-landscape {
|
||||
position: fixed;
|
||||
position: absolute;
|
||||
top: 50%; left: 50%; right: auto; bottom: auto;
|
||||
width: 100vh; height: 100vw;
|
||||
width: 100dvh; height: 100dvw;
|
||||
transform: translate(-50%, -50%) rotate(90deg);
|
||||
transform-origin: center center;
|
||||
z-index: 45;
|
||||
background: #000;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.desktop-dock-panel {
|
||||
|
||||
+5
-25
@@ -1,5 +1,4 @@
|
||||
import React, { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { api, platform as envPlatform } from "./api";
|
||||
import { isStrictSecurity, setStrictSecurity as setHtmlStrictSecurity } from "./html";
|
||||
import type { User } from "./types";
|
||||
@@ -121,8 +120,6 @@ type Store = {
|
||||
toggleFollowLocal: (uid: number) => boolean;
|
||||
theater: boolean; setTheater: (v: boolean | ((p: boolean) => boolean)) => void;
|
||||
fs: boolean; setFs: (v: boolean | ((p: boolean) => boolean)) => void;
|
||||
/** 清屏模式(单击屏幕消除所有控件,只保留纯视频内容) */
|
||||
clean: boolean; setClean: (v: boolean | ((p: boolean) => boolean)) => void;
|
||||
muted: boolean; setMuted: (v: boolean | ((p: boolean) => boolean)) => void;
|
||||
muteOnStartup: boolean; setMuteOnStartup: (on: boolean) => void;
|
||||
volume: number; setVolume: (v: number) => void;
|
||||
@@ -145,7 +142,6 @@ export function AppProvider({ children }: { children: React.ReactNode }) {
|
||||
const [toasts, setToasts] = useState<Toast[]>([]);
|
||||
const [theater, setTheaterState] = useState(false);
|
||||
const [fs, setFsState] = useState(false);
|
||||
const [clean, setCleanState] = useState(false);
|
||||
const [strictSecurity, setStrictSecurityState] = useState<boolean>(isStrictSecurity);
|
||||
const [cliRelaxed, setCliRelaxed] = useState(false);
|
||||
const [strictSecurityReady, setStrictSecurityReady] = useState(false);
|
||||
@@ -193,15 +189,11 @@ export function AppProvider({ children }: { children: React.ReactNode }) {
|
||||
window.setTimeout(() => setToasts((t) => t.filter((x) => x.id !== id)), 2200);
|
||||
}, []);
|
||||
|
||||
const setTab = useCallback((t: Tab) => { setTabRaw(t); setStack([]); setCleanState(false); }, []);
|
||||
const setTab = useCallback((t: Tab) => { setTabRaw(t); setStack([]); }, []);
|
||||
const push = useCallback((pg: PageInput) => {
|
||||
setCleanState(false);
|
||||
setStack((s) => [...s, { ...pg, key: `p${++seq}` } as Page]);
|
||||
}, []);
|
||||
const pop = useCallback(() => {
|
||||
setCleanState(false);
|
||||
setStack((s) => s.slice(0, -1));
|
||||
}, []);
|
||||
const pop = useCallback(() => setStack((s) => s.slice(0, -1)), []);
|
||||
|
||||
const toggleLikeLocal = useCallback((id: number) => {
|
||||
let on = false;
|
||||
@@ -261,18 +253,7 @@ export function AppProvider({ children }: { children: React.ReactNode }) {
|
||||
}, []);
|
||||
|
||||
const setFs = useCallback((v: boolean | ((prev: boolean) => boolean)) => {
|
||||
setFsState((prev) => {
|
||||
const next = typeof v === "function" ? (v as (p: boolean) => boolean)(prev) : v;
|
||||
if (!next) {
|
||||
invoke("set_orientation", { landscape: false }).catch(() => {});
|
||||
try { screen.orientation?.unlock?.(); } catch { /* ignore */ }
|
||||
}
|
||||
return next;
|
||||
});
|
||||
}, []);
|
||||
|
||||
const setClean = useCallback((v: boolean | ((prev: boolean) => boolean)) => {
|
||||
setCleanState((prev) => (typeof v === "function" ? (v as (p: boolean) => boolean)(prev) : v));
|
||||
setFsState((prev) => (typeof v === "function" ? (v as (p: boolean) => boolean)(prev) : v));
|
||||
}, []);
|
||||
|
||||
const setMuted = useCallback((v: boolean | ((prev: boolean) => boolean)) => {
|
||||
@@ -295,8 +276,7 @@ export function AppProvider({ children }: { children: React.ReactNode }) {
|
||||
isLiked: (id) => p.likes.includes(id),
|
||||
isFav: (id) => p.favs.includes(id),
|
||||
toggleLikeLocal, toggleFavLocal, toggleFollowLocal, addHistory, clearHistory,
|
||||
muted: p.muted, setMuted, volume: p.volume, setVolume,
|
||||
theater, setTheater, fs, setFs, clean, setClean,
|
||||
muted: p.muted, setMuted, volume: p.volume, setVolume, theater, setTheater, fs, setFs,
|
||||
muteOnStartup: p.muteOnStartup, setMuteOnStartup,
|
||||
searchHist: p.searchHist, addSearch, clearSearchHist,
|
||||
strictSecurity, strictSecurityReady, securityPending, cliRelaxed, setStrictSecurity,
|
||||
@@ -304,7 +284,7 @@ export function AppProvider({ children }: { children: React.ReactNode }) {
|
||||
}), [theme, tab, setTab, stack, push, pop, user, loginOpen, logout,
|
||||
p, toggleLikeLocal, toggleFavLocal, toggleFollowLocal, addHistory, clearHistory,
|
||||
setMuted, setMuteOnStartup, setVolume, addSearch, clearSearchHist, strictSecurity, strictSecurityReady, securityPending, cliRelaxed, setStrictSecurity,
|
||||
toasts, toast, theater, setTheater, fs, setFs, clean, setClean]);
|
||||
toasts, toast, theater, setTheater, fs, setFs]);
|
||||
|
||||
return <Ctx.Provider value={value}>{children}</Ctx.Provider>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user