From b5a8a7f6c60142f520118276f58da1e36b63793e Mon Sep 17 00:00:00 2001 From: kuekhaoyang Date: Thu, 12 Mar 2026 23:20:29 +0800 Subject: [PATCH] feat: enhance HLS player to prefer H.264 for compatibility with HEVC levels and update VideoGroupCard to include premium parameter in URL --- components/player/hooks/useHlsPlayer.ts | 27 ++++++++++++++++++------- components/search/VideoGroupCard.tsx | 6 +++++- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/components/player/hooks/useHlsPlayer.ts b/components/player/hooks/useHlsPlayer.ts index 4b4ec8c..8d186af 100644 --- a/components/player/hooks/useHlsPlayer.ts +++ b/components/player/hooks/useHlsPlayer.ts @@ -135,17 +135,30 @@ export function useHlsPlayer({ // Manifest Parsed Handler hls.on(Hls.Events.MANIFEST_PARSED, () => { - // Check for HEVC + // Filter HEVC levels: prefer H.264 for compatibility if (hls) { const levels = hls.levels; if (levels && levels.length > 0) { - const hasHEVC = levels.some(level => - level.videoCodec?.toLowerCase().includes('hev') || - level.videoCodec?.toLowerCase().includes('h265') - ); + const h264Indices: number[] = []; + let hasHEVC = false; + levels.forEach((level, index) => { + const codec = level.videoCodec?.toLowerCase() || ''; + if (codec.includes('hev') || codec.includes('h265') || codec.includes('hvc')) { + hasHEVC = true; + } else { + h264Indices.push(index); + } + }); if (hasHEVC) { - console.warn('[HLS] ⚠️ HEVC detected'); - onError?.('检测到 HEVC/H.265 编码,当前浏览器可能不支持'); + if (h264Indices.length > 0) { + // H.264 alternatives exist — lock to first H.264 level + console.info('[HLS] HEVC detected, using H.264 level for compatibility'); + hls.currentLevel = h264Indices[0]; + } else { + // All levels are HEVC — warn user + console.warn('[HLS] ⚠️ All levels are HEVC, browser may not support'); + onError?.('检测到 HEVC/H.265 编码,当前浏览器可能不支持'); + } } } } diff --git a/components/search/VideoGroupCard.tsx b/components/search/VideoGroupCard.tsx index 69a3c31..ce83b45 100644 --- a/components/search/VideoGroupCard.tsx +++ b/components/search/VideoGroupCard.tsx @@ -76,8 +76,12 @@ export const VideoGroupCard = memo(({ } } + if (isPremium) { + params.set('premium', '1'); + } + return `/player?${params.toString()}`; - }, [representative, videos]); + }, [representative, videos, isPremium]); return (