feat: dplayer

This commit is contained in:
mozzie 2023-03-02 16:45:05 +08:00
parent c215c6fa37
commit 8cd3f5b6d2

View File

@ -1,6 +1,6 @@
import { useEffect, useRef } from "react"; import { useEffect, useRef } from "react";
import DPlayer from "dplayer"; import DPlayer, { DPlayerOptions } from "dplayer";
import './index.less' import "./index.less";
interface IProps { interface IProps {
video: { video: {
@ -12,23 +12,19 @@ interface IProps {
function Player(props: IProps) { function Player(props: IProps) {
const playerRef = useRef<any>(); const playerRef = useRef<any>();
const baseConf: DPlayerOptions = {
container: playerRef.current,
preload: "auto",
playbackSpeed: [0.5, 0.75, 1, 1.25, 1.5, 2],
screenshot: true,
pluginOptions: {
hls: {},
},
};
useEffect(() => { useEffect(() => {
if (props.video) { if (props.video) {
new DPlayer({ new DPlayer({ ...baseConf, video: { ...props.video, type: "hls" } });
container: playerRef.current,
video: {
...props.video,
type: "hls",
},
preload: "auto",
playbackSpeed: [0.5, 0.75, 1, 1.25, 1.5, 2],
screenshot: true,
pluginOptions: {
hls: {
// hls config
},
},
});
} }
}, [props.video]); }, [props.video]);