From 6871d061fc268d85517ad4270ecd57d83e187561 Mon Sep 17 00:00:00 2001 From: Developer Date: Tue, 10 Mar 2026 22:52:05 +0800 Subject: [PATCH] feat: add orientation lock and dual-instance fullscreen to VideoPlayer --- components/VideoPlayer.tsx | 76 ++++++++++++++++++++++++++------------ 1 file changed, 52 insertions(+), 24 deletions(-) diff --git a/components/VideoPlayer.tsx b/components/VideoPlayer.tsx index 264a025..30758c2 100644 --- a/components/VideoPlayer.tsx +++ b/components/VideoPlayer.tsx @@ -1,10 +1,8 @@ -import React, { useState } from 'react'; -import { View, StyleSheet, Dimensions, Text, Platform, Modal, StatusBar } from 'react-native'; +import React, { useState, useRef, useEffect } from 'react'; +import { View, StyleSheet, Text, Platform, Modal, StatusBar, useWindowDimensions } from 'react-native'; +import * as ScreenOrientation from 'expo-screen-orientation'; import { NativeVideoPlayer } from './NativeVideoPlayer'; -import type { PlayUrlResponse } from '../services/types'; - -const { width } = Dimensions.get('window'); -const VIDEO_HEIGHT = width * 0.5625; +import type { PlayUrlResponse, DanmakuItem } from '../services/types'; interface Props { playData: PlayUrlResponse | null; @@ -14,14 +12,38 @@ interface Props { onMiniPlayer?: () => void; bvid?: string; cid?: number; + danmakus?: DanmakuItem[]; + onTimeUpdate?: (t: number) => void; } -export function VideoPlayer({ playData, qualities, currentQn, onQualityChange, onMiniPlayer, bvid, cid }: Props) { +export function VideoPlayer({ playData, qualities, currentQn, onQualityChange, onMiniPlayer, bvid, cid, danmakus, onTimeUpdate }: Props) { const [fullscreen, setFullscreen] = useState(false); + const { width } = useWindowDimensions(); + const VIDEO_HEIGHT = width * 0.5625; + const lastTimeRef = useRef(0); + + const handleEnterFullscreen = async () => { + setFullscreen(true); + if (Platform.OS !== 'web') + await ScreenOrientation.lockAsync(ScreenOrientation.OrientationLock.LANDSCAPE_RIGHT); + }; + + const handleExitFullscreen = async () => { + setFullscreen(false); + if (Platform.OS !== 'web') + await ScreenOrientation.lockAsync(ScreenOrientation.OrientationLock.PORTRAIT_UP); + }; + + useEffect(() => { + return () => { + if (Platform.OS !== 'web') + ScreenOrientation.lockAsync(ScreenOrientation.OrientationLock.PORTRAIT_UP); + }; + }, []); if (!playData) { return ( - + 视频加载中... ); @@ -30,7 +52,7 @@ export function VideoPlayer({ playData, qualities, currentQn, onQualityChange, o if (Platform.OS === 'web') { const url = playData.durl?.[0]?.url ?? ''; return ( - +