From 8cd3f5b6d21be22bf61708003689035e132da0f4 Mon Sep 17 00:00:00 2001 From: mozzie Date: Thu, 2 Mar 2023 16:45:05 +0800 Subject: [PATCH] feat: dplayer --- .../CourseDetail/components/DPlayer/index.tsx | 30 ++++++++----------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/apps/web-main/src/view/CourseDetail/components/DPlayer/index.tsx b/apps/web-main/src/view/CourseDetail/components/DPlayer/index.tsx index 6c1d779..c544bea 100644 --- a/apps/web-main/src/view/CourseDetail/components/DPlayer/index.tsx +++ b/apps/web-main/src/view/CourseDetail/components/DPlayer/index.tsx @@ -1,6 +1,6 @@ import { useEffect, useRef } from "react"; -import DPlayer from "dplayer"; -import './index.less' +import DPlayer, { DPlayerOptions } from "dplayer"; +import "./index.less"; interface IProps { video: { @@ -12,23 +12,19 @@ interface IProps { function Player(props: IProps) { const playerRef = useRef(); + const baseConf: DPlayerOptions = { + container: playerRef.current, + preload: "auto", + playbackSpeed: [0.5, 0.75, 1, 1.25, 1.5, 2], + screenshot: true, + pluginOptions: { + hls: {}, + }, + }; + useEffect(() => { if (props.video) { - new DPlayer({ - 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 - }, - }, - }); + new DPlayer({ ...baseConf, video: { ...props.video, type: "hls" } }); } }, [props.video]);