import React, { useState, useRef, useEffect } from 'react'; import { View, StyleSheet, Dimensions, TouchableOpacity, Text, Modal, } from 'react-native'; import Video, { VideoRef } from 'react-native-video'; import { Ionicons } from '@expo/vector-icons'; import type { PlayUrlResponse } from '../services/types'; import { buildDashDataUri } from '../utils/dash'; const { width } = Dimensions.get('window'); const VIDEO_HEIGHT = width * 0.5625; const BILIBILI_HEADERS = { Referer: 'https://www.bilibili.com', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36', }; interface Props { playData: PlayUrlResponse | null; qualities: { qn: number; desc: string }[]; currentQn: number; onQualityChange: (qn: number) => void; onFullscreen: () => void; onMiniPlayer?: () => void; style?: object; onProgress?: (currentTime: number, duration: number) => void; seekTo?: { t: number; v: number }; } export function NativeVideoPlayer({ playData, qualities, currentQn, onQualityChange, onFullscreen, onMiniPlayer, style, onProgress, seekTo, }: Props) { const [showQuality, setShowQuality] = useState(false); const videoRef = useRef(null); const currentDesc = qualities.find(q => q.qn === currentQn)?.desc ?? (currentQn ? String(currentQn) : 'HD'); const isDash = !!playData?.dash; const url = isDash ? buildDashDataUri(playData!, currentQn) : playData?.durl?.[0]?.url; useEffect(() => { if (seekTo !== undefined) videoRef.current?.seek(seekTo.t); }, [seekTo]); return ( {url ? (