import React, { Component, Fragment } from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import Video from './Video';
import BufferingLoader from './BufferingLoader';
import ControlBar from './ControlBar';
import styles from './styles';
class Player extends Component {
constructor(props) {
super(props);
this.videoRef = React.createRef();
this.state = {
paused: null,
time: null,
duration: null,
buffering: null,
volume: null,
subtitleTracks: [],
selectedSubtitleTrackId: null,
subtitleSize: null,
subtitleDelay: null,
subtitleDarkBackground: null
};
}
shouldComponentUpdate(nextProps, nextState) {
return nextState.paused !== this.state.paused ||
nextState.time !== this.state.time ||
nextState.duration !== this.state.duration ||
nextState.buffering !== this.state.buffering ||
nextState.volume !== this.state.volume ||
nextState.subtitleTracks !== this.state.subtitleTracks ||
nextState.selectedSubtitleTrackId !== this.state.selectedSubtitleTrackId ||
nextState.subtitleSize !== this.state.subtitleSize ||
nextState.subtitleDelay !== this.state.subtitleDelay ||
nextState.subtitleDarkBackground !== this.state.subtitleDarkBackground;
}
componentDidMount() {
this.dispatch('command', 'load', this.props.stream, {});
this.dispatch('command', 'addSubtitleTracks', [{
url: 'https://raw.githubusercontent.com/caitp/ng-media/master/example/assets/captions/bunny-en.vtt',
origin: 'Github',
label: 'English'
}]);
this.dispatch('setProp', 'selectedSubtitleTrackId', 'https://raw.githubusercontent.com/caitp/ng-media/master/example/assets/captions/bunny-en.vtt');
}
onEnded = () => {
alert('ended');
}
onError = (error) => {
alert(error.message);
}
onPropValue = (propName, propValue) => {
this.setState({ [propName]: propValue });
}
onPropChanged = (propName, propValue) => {
this.setState({ [propName]: propValue });
}
dispatch = (...args) => {
this.videoRef.current && this.videoRef.current.dispatch(...args);
}
renderVideo() {
return (