import React, { useState, useRef, useEffect } from 'react'; import { StyleSheet, View, StatusBar, Alert, ActivityIndicator } from 'react-native'; import { Text, IconButton, Surface } from 'react-native-paper'; import { SafeAreaView } from 'react-native-safe-area-context'; import { useRoute, useNavigation } from '@react-navigation/native'; import Video, { type VideoRef } from 'react-native-video'; export default function VideoPlayerScreen() { const route = useRoute(); const navigation = useNavigation(); const { cameraName, streamUrl } = route.params; const videoRef = useRef(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const [paused, setPaused] = useState(false); const [muted, setMuted] = useState(true); useEffect(() => { if (!streamUrl) { setError('无视频流地址'); setLoading(false); } }, [streamUrl]); const handleLoad = () => { setLoading(false); setError(null); }; const handleError = (e: any) => { setLoading(false); const msg = e?.error?.errorString || e?.error?.localizedDescription || '视频加载失败'; setError(msg); }; return ( navigation.goBack()} /> {cameraName} {error ? ( {error} ) : ( <> {streamUrl ? ( 流地址: {streamUrl || 'N/A'} ); } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: '#000', }, header: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', backgroundColor: '#1A1815', paddingHorizontal: 4, }, headerTitle: { color: 'white', fontSize: 18, fontWeight: '500', flex: 1, textAlign: 'center', }, videoContainer: { flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: '#000', }, video: { width: '100%', height: '100%', }, loadingOverlay: { ...StyleSheet.absoluteFillObject, justifyContent: 'center', alignItems: 'center', backgroundColor: 'rgba(26,24,21,0.5)', }, loadingText: { color: 'white', marginTop: 12, }, controlsOverlay: { position: 'absolute', bottom: 24, left: 0, right: 0, alignItems: 'center', }, controlBar: { flexDirection: 'row', alignItems: 'center', backgroundColor: 'rgba(26,24,21,0.6)', borderRadius: 28, paddingHorizontal: 8, elevation: 0, }, errorContainer: { alignItems: 'center', justifyContent: 'center', }, errorText: { color: '#B8B3AA', fontSize: 16, marginTop: 8, textAlign: 'center', paddingHorizontal: 32, }, footer: { padding: 12, backgroundColor: '#1A1815', }, streamUrl: { color: '#8C8780', fontSize: 11, }, });