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>();
useEffect(() => { const baseConf: DPlayerOptions = {
if (props.video) {
new DPlayer({
container: playerRef.current, container: playerRef.current,
video: {
...props.video,
type: "hls",
},
preload: "auto", preload: "auto",
playbackSpeed: [0.5, 0.75, 1, 1.25, 1.5, 2], playbackSpeed: [0.5, 0.75, 1, 1.25, 1.5, 2],
screenshot: true, screenshot: true,
pluginOptions: { pluginOptions: {
hls: { hls: {},
// hls config
}, },
}, };
});
useEffect(() => {
if (props.video) {
new DPlayer({ ...baseConf, video: { ...props.video, type: "hls" } });
} }
}, [props.video]); }, [props.video]);