From 624d7cb183b0e01c40cab814ff1713b09d1df64b Mon Sep 17 00:00:00 2001 From: sunlizhou <296190577@qq.com> Date: Thu, 26 Oct 2023 17:22:17 +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=E5=88=86=E6=A0=B7=E5=BC=8F=E6=8A=BD?= =?UTF-8?q?=E7=A6=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/videoPro/index.module.scss | 11 +++++ src/components/videoPro/index.tsx | 60 ++++++++++++----------- 2 files changed, 42 insertions(+), 29 deletions(-) diff --git a/src/components/videoPro/index.module.scss b/src/components/videoPro/index.module.scss index d1dc03c..c95d579 100644 --- a/src/components/videoPro/index.module.scss +++ b/src/components/videoPro/index.module.scss @@ -2,3 +2,14 @@ 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 477e1af..bfb378a 100644 --- a/src/components/videoPro/index.tsx +++ b/src/components/videoPro/index.tsx @@ -14,18 +14,6 @@ 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) // 视频长度 单位秒 @@ -37,6 +25,15 @@ 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('组件加载') @@ -44,7 +41,16 @@ 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) { @@ -60,7 +66,6 @@ const VideoPro:FC = ({src,onRef,showFull}) => { time.current = setTimeout(() => { setShowMenu(false) },5000) - } function bindTimeupdateFun(e) { @@ -126,17 +131,6 @@ 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) { // 视频跳转到指定位置 @@ -166,10 +160,18 @@ const VideoPro:FC = ({src,onRef,showFull}) => { onEnded={bindEnded} onFullScreenChange={onFullScreenChange} > - - + + { !isPlay && showMenu && - + } @@ -189,8 +191,8 @@ const VideoPro:FC = ({src,onRef,showFull}) => { {total_duration} { showFull && <> - {isFull? {videoContext.current.exitFullScreen()}} src={unfull} /> - : {videoContext.current.requestFullScreen({direction:90})}} />} + {isFull? videoContext.current.exitFullScreen()} src={unfull} /> + : videoContext.current.requestFullScreen({direction:90})} />} }