Added video player

This commit is contained in:
2022-07-06 14:05:15 +02:00
parent 1a0f0fda89
commit 557f37aaa4
4 changed files with 499 additions and 6 deletions

View File

@@ -0,0 +1,34 @@
import React from "react";
import videojs from "video.js";
import "video.js/dist/video-js.css";
const VideoPlayer = ({options, src}:{options:videojs.PlayerOptions, src:{src:string, type:string}}) => {
const videoNode = React.useRef<HTMLVideoElement>(null);
const player = React.useRef<videojs.Player>();
const srcLoaded = React.useRef<boolean>(false);
const initialized = React.useRef<boolean>(false);
React.useEffect(() => {
if(!srcLoaded.current) {
if(videoNode.current && !initialized.current) {
videojs(videoNode.current, {
...options,
...{
sources: [src]
}
}).ready(function() {
player.current = this;
srcLoaded.current = true;
});
initialized.current = true;
}
} else {
player.current?.src(src);
player.current?.load();
}
}, [options, src]);
return <video ref={videoNode} className="video-js" />;
};
export default VideoPlayer;