Files
JKVideo/components/VideoPlayer.tsx

42 lines
1.0 KiB
TypeScript
Raw Normal View History

2026-03-06 14:52:28 +08:00
import React from 'react';
2026-03-06 12:58:41 +08:00
import { View, StyleSheet, Dimensions, Text, Platform } from 'react-native';
2026-03-06 14:52:28 +08:00
import { NativeVideoPlayer } from './NativeVideoPlayer';
const { width } = Dimensions.get('window');
const VIDEO_HEIGHT = width * 0.5625;
interface Props {
uri: string | null;
}
export function VideoPlayer({ uri }: Props) {
if (!uri) {
return (
<View style={[styles.container, styles.placeholder]}>
<Text style={styles.placeholderText}>...</Text>
</View>
);
}
2026-03-06 12:58:41 +08:00
if (Platform.OS === 'web') {
return (
<View style={styles.container}>
<video
src={uri}
style={{ width: '100%', height: '100%', backgroundColor: '#000' } as any}
controls
playsInline
/>
</View>
);
}
return <NativeVideoPlayer uri={uri} />;
}
const styles = StyleSheet.create({
container: { width, height: VIDEO_HEIGHT, backgroundColor: '#000' },
placeholder: { justifyContent: 'center', alignItems: 'center' },
placeholderText: { color: '#fff', fontSize: 14 },
});