From e3ced26435a062c33ca8680ed57fa4950d552f6b Mon Sep 17 00:00:00 2001 From: sunlizhou <296190577@qq.com> Date: Thu, 26 Oct 2023 17:29:06 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89ui=E8=A7=86=E9=A2=91?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E9=83=A8=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/videoPro/index.module.scss | 15 ------ src/components/videoPro/index.tsx | 61 +++++++++++------------ 2 files changed, 29 insertions(+), 47 deletions(-) diff --git a/src/components/videoPro/index.module.scss b/src/components/videoPro/index.module.scss index c95d579..e69de29 100644 --- a/src/components/videoPro/index.module.scss +++ b/src/components/videoPro/index.module.scss @@ -1,15 +0,0 @@ -.container{ - width:750rpx; - height:600rpx; -} -.control{ - display:flex; - flex-direction:column; - box-sizing:border-box; -} -.centerBtnBg{ - width: 50px; - height:50px; - background-color: rgba(0,0,0,0.5); - box-sizing: border-box; -} diff --git a/src/components/videoPro/index.tsx b/src/components/videoPro/index.tsx index bfb378a..505c4ca 100644 --- a/src/components/videoPro/index.tsx +++ b/src/components/videoPro/index.tsx @@ -14,6 +14,18 @@ type Props = { } const VideoPro:FC = ({src,onRef,showFull}) => { + const globalData = Taro.getApp().globalData + + if(onRef){ + //用useImperativeHandle暴露一些外部ref能访问的属性 + useImperativeHandle(onRef, () => { + return { + func: pause, + } + }) + } + + // 视频ui控制需要的响应式数据 const videoContext = useRef() const [isPlay, setIsPlay] = useState(false) const [duration,setDuration] = useState(0) // 视频长度 单位秒 @@ -25,15 +37,6 @@ const VideoPro:FC = ({src,onRef,showFull}) => { const [isFull,setIsFull] = useState(false) const time = useRef() - const globalData = Taro.getApp().globalData - if(onRef){ - //用useImperativeHandle暴露一些外部ref能访问的属性 - useImperativeHandle(onRef, () => { - return { - func: pause, - } - }) - } useEffect(() => { console.log('组件加载') @@ -41,16 +44,7 @@ const VideoPro:FC = ({src,onRef,showFull}) => { updateState.current = true }, []); - function play(e){ - e.stopPropagation(); - videoContext.current.play() - setIsPlay(true) - } - function pause(){ - setIsPlay(false) - videoContext.current.pause() - } function onTouchStart(){ if(!showMenu) { @@ -66,6 +60,7 @@ const VideoPro:FC = ({src,onRef,showFull}) => { time.current = setTimeout(() => { setShowMenu(false) },5000) + } function bindTimeupdateFun(e) { @@ -131,6 +126,17 @@ const VideoPro:FC = ({src,onRef,showFull}) => { } } + + function play(e){ + e.stopPropagation(); + videoContext.current.play() + setIsPlay(true) + } + + function pause(){ + setIsPlay(false) + videoContext.current.pause() + } function sliderOnChange(e){ if (duration) { // 视频跳转到指定位置 @@ -148,7 +154,6 @@ const VideoPro:FC = ({src,onRef,showFull}) => {