From 682a3a897720d653539f0036dc9c641739f3d1d8 Mon Sep 17 00:00:00 2001 From: Joe Date: Fri, 21 Feb 2025 17:30:51 +0800 Subject: [PATCH] up --- package.json | 1 + src/components/AliPlayer/index.tsx | 123 ++++--------------------- src/global.tsx | 12 +++ src/pages/RequirementAudits/detail.tsx | 10 +- src/pages/RequirementAudits/index.tsx | 3 +- src/typings.d.ts | 1 + 6 files changed, 43 insertions(+), 107 deletions(-) diff --git a/package.json b/package.json index 0b5400b..d463192 100644 --- a/package.json +++ b/package.json @@ -54,6 +54,7 @@ "@dnd-kit/sortable": "^8.0.0", "@dnd-kit/utilities": "^3.2.2", "@umijs/route-utils": "^2.2.2", + "aliyun-aliplayer": "^2.29.1", "antd": "^5.2.2", "antd-img-crop": "^4.23.0", "braft-editor": "^2.3.9", diff --git a/src/components/AliPlayer/index.tsx b/src/components/AliPlayer/index.tsx index 5362d1a..ed0b47b 100644 --- a/src/components/AliPlayer/index.tsx +++ b/src/components/AliPlayer/index.tsx @@ -1,6 +1,7 @@ -import React, { useEffect, useRef, useState } from 'react'; -import { Button, Slider, Select, Space, Card } from 'antd'; -import { PauseCircleOutlined, PlayCircleOutlined, ExpandOutlined } from '@ant-design/icons'; +import React, { useEffect, useState } from 'react'; +import { Card } from 'antd'; +import Aliplayer from 'aliyun-aliplayer'; +import 'aliyun-aliplayer/build/skins/default/aliplayer-min.css'; interface AliPlayerProps { vid: string; @@ -15,115 +16,31 @@ const AliPlayer: React.FC = ({ width = '100%', height = 500 }) => { - const playerRef = useRef(null); - const containerRef = useRef(null); - const [playing, setPlaying] = useState(false); - const [currentTime, setCurrentTime] = useState(0); - const [duration, setDuration] = useState(0); - const [playbackRate, setPlaybackRate] = useState(1); + const [player, setPlayer] = useState(null); // 播放器实例 // 初始化播放器 useEffect(() => { - const link = document.createElement('link'); - const script = document.createElement('script'); - link.rel = "stylesheet" - link.href = 'https://g.alicdn.com/apsara-media-box/imp-web-player/2.29.1/skins/default/aliplayer-min.css' - script.src = 'https://g.alicdn.com/apsara-media-box/imp-web-player/2.29.1/aliplayer-min.js'; - script.onload = () => { - if (containerRef.current) { - playerRef.current = new (window as any).Aliplayer({ - id: containerRef.current, - vid: vid, - playauth: playAuth, - width: width, - height: height, - autoplay: false, - encryptType: 1, - }, () => { - // 播放器准备就绪 - setDuration(playerRef.current.getDuration()); - - // 绑定事件 - playerRef.current.on('play', () => setPlaying(true)); - playerRef.current.on('pause', () => setPlaying(false)); - playerRef.current.on('ended', () => setPlaying(false)); - playerRef.current.on('timeupdate', (currentTime: number) => { - setCurrentTime(currentTime); - }); - }); + if (player) { + player.dispose(); + } + // 更多使用方法请参考接入文档:https://help.aliyun.com/zh/vod/developer-reference/integration + const playerInstance = new Aliplayer( + { + id: "container", + width: width, + height: height, + vid, + playauth: playAuth, + disableSeek: true, } - }; - document.head.appendChild(link); - document.head.appendChild(script); + ); - return () => { - if (playerRef.current) { - playerRef.current.dispose(); - } - document.head.removeChild(link); - document.head.removeChild(script); - }; + setPlayer(playerInstance); }, [vid, playAuth]); - // 播放/暂停控制 - const togglePlay = () => { - if (playing) { - playerRef.current.pause(); - } else { - playerRef.current.play(); - } - }; - - // 进度条跳转 - const handleSeek = (value: number) => { - playerRef.current.seek(value); - }; - - // 倍速播放 - const handleSpeedChange = (value: number) => { - playerRef.current.setPlaybackRate(value); - setPlaybackRate(value); - }; - - // 全屏 - const handleFullscreen = () => { - playerRef.current.requestFullscreen(); - }; - return ( -
- - -