blakeblackshear.frigate/web/src/components/VideoPlayer.jsx

54 lines
1.2 KiB
React
Raw Normal View History

2021-05-28 19:13:48 +02:00
import { h, Component } from 'preact';
import videojs from 'video.js';
import 'videojs-playlist';
import 'videojs-seek-buttons';
2021-05-28 19:13:48 +02:00
import 'video.js/dist/video-js.css';
import 'videojs-seek-buttons/dist/videojs-seek-buttons.css';
2021-05-28 19:13:48 +02:00
const defaultOptions = {
controls: true,
playbackRates: [0.5, 1, 2, 4, 8],
2021-05-28 19:13:48 +02:00
fluid: true,
};
export default class VideoPlayer extends Component {
componentDidMount() {
const { options, onReady = () => {} } = this.props;
const videoJsOptions = {
...defaultOptions,
...options,
};
this.player = videojs(this.videoNode, videoJsOptions, function onPlayerReady() {
onReady(this);
});
this.player.seekButtons({
forward: 30,
back: 15,
});
2021-05-28 19:13:48 +02:00
}
componentWillUnmount() {
const { onDispose = () => {} } = this.props;
2021-05-28 19:13:48 +02:00
if (this.player) {
this.player.dispose();
onDispose();
2021-05-28 19:13:48 +02:00
}
}
// shouldComponentUpdate() {
// return false;
// }
2021-05-28 19:13:48 +02:00
render() {
2021-06-02 08:41:26 +02:00
const { style, children } = this.props;
2021-05-28 19:13:48 +02:00
return (
<div style={style}>
<div data-vjs-player>
2021-06-02 08:41:26 +02:00
<video ref={(node) => (this.videoNode = node)} className="video-js vjs-default-skin" controls playsinline />
{children}
2021-05-28 19:13:48 +02:00
</div>
</div>
);
}
}