import React, { createRef, useRef } from "react"; import { StyleSheet, View } from "react-native"; import { VLCPlayer } from "react-native-vlc-media-player"; import MediaControls, { PLAYER_STATES } from "react-native-media-controls"; import colors from "../../res/colors"; type Props = { url: string; thumbnail: string; width: number; height: number; isplaying: boolean; }; type MyState = { isPlaying: boolean; isMuted: boolean; isLoading: boolean; playerState: any; isPaused: boolean; isFullScreen: boolean; duration: number; currentTime: number; setCurrentTime: number; position: any; }; export default class VideoPlayerController extends React.Component< Props, MyState > { constructor(props) { super(props); } state: MyState = { isMuted: false, isLoading: true, // playerState: this.props.isplaying // ? PLAYER_STATES.PLAYING // : PLAYER_STATES.PAUSED, playerState: PLAYER_STATES.PLAYING, isPaused: true, isPlaying: false, isFullScreen: false, duration: 0, currentTime: 0, setCurrentTime: 0, position: 0.0, }; _player: any; videoPlayer: any; componentDidMount = () => { console.log("video props->", this.props); }; onReplay = () => { this.setState({ isPlaying: !this.state.isPlaying, playerState: PLAYER_STATES.PLAYING, }); }; onLoadStart = () => this.setState({ isLoading: true }); onSeeking = (currentTime: any) => { this.setState({ setCurrentTime: currentTime, position: currentTime / this.state.duration, }); }; noop = () => { this.setState({ isFullScreen: !this.state.isFullScreen }); }; onEnd = () => { this.setState({ playerState: PLAYER_STATES.ENDED, isPlaying: false, isPaused: true, }); }; _onLoadEnd = (data: any) => { this.setState({ duration: data.duration, isLoading: false, }); }; onProgress = (data: any) => { if (this.state.isLoading) { this.setState({ isLoading: false }); } this.setState({ currentTime: data.currentTime / 1000, duration: data.duration / 1000, }); }; // onPlaying = (data: any) => { console.log("onPlaying", data); }; _onLoadStart = (data: any) => { this.setState({ isLoading: false, isPlaying: false, playerState: PLAYER_STATES.PLAYING, }); }; onSeek = (seek: any) => {}; onPaused = (playerState: any) => { console.log("pause via controller"); this.setState({ isPlaying: !this.state.isPlaying, isPaused: !this.state.isPaused, playerState: playerState, }); }; _onStopped = (data: any) => {}; _onPlayerPaused = (data: any) => {}; render() { return ( // this.setState( // { // isLoading: false, // }, // () => { // this.setState({ // playerState: PLAYER_STATES.PAUSED, // }); // } // ) // } onBuffering={(buffer) => this.setState({ isLoading: true })} onPlaying={this.onPlaying} resizeMode="cover" repeat={false} style={{ height: this.props.height, width: this.props.width }} /> {/* ); } } const styles = StyleSheet.create({ container: { flex: 1, }, backgroundVideo: { flex: 1, width: "100%", position: "absolute", top: 0, left: 0, bottom: 0, right: 0, }, toolbar: { marginTop: 30, backgroundColor: "white", padding: 10, borderRadius: 5, }, mediaPlayer: { position: "absolute", top: 0, left: 0, bottom: 0, right: 0, backgroundColor: "black", }, });