自定义ui视频组件部分样式抽离

master
一杯沧海 1 year ago
parent c421e30b71
commit 624d7cb183
  1. 11
      src/components/videoPro/index.module.scss
  2. 60
      src/components/videoPro/index.tsx

@ -2,3 +2,14 @@
width:750rpx; width:750rpx;
height:600rpx; 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;
}

@ -14,18 +14,6 @@ type Props = {
} }
const VideoPro:FC<Props> = ({src,onRef,showFull}) => { const VideoPro:FC<Props> = ({src,onRef,showFull}) => {
const globalData = Taro.getApp().globalData
if(onRef){
//用useImperativeHandle暴露一些外部ref能访问的属性
useImperativeHandle(onRef, () => {
return {
func: pause,
}
})
}
// 视频ui控制需要的响应式数据
const videoContext = useRef<any>() const videoContext = useRef<any>()
const [isPlay, setIsPlay] = useState(false) const [isPlay, setIsPlay] = useState(false)
const [duration,setDuration] = useState(0) // 视频长度 单位秒 const [duration,setDuration] = useState(0) // 视频长度 单位秒
@ -37,6 +25,15 @@ const VideoPro:FC<Props> = ({src,onRef,showFull}) => {
const [isFull,setIsFull] = useState(false) const [isFull,setIsFull] = useState(false)
const time = useRef<any>() const time = useRef<any>()
const globalData = Taro.getApp().globalData
if(onRef){
//用useImperativeHandle暴露一些外部ref能访问的属性
useImperativeHandle(onRef, () => {
return {
func: pause,
}
})
}
useEffect(() => { useEffect(() => {
console.log('组件加载') console.log('组件加载')
@ -44,7 +41,16 @@ const VideoPro:FC<Props> = ({src,onRef,showFull}) => {
updateState.current = true updateState.current = true
}, []); }, []);
function play(e){
e.stopPropagation();
videoContext.current.play()
setIsPlay(true)
}
function pause(){
setIsPlay(false)
videoContext.current.pause()
}
function onTouchStart(){ function onTouchStart(){
if(!showMenu) { if(!showMenu) {
@ -60,7 +66,6 @@ const VideoPro:FC<Props> = ({src,onRef,showFull}) => {
time.current = setTimeout(() => { time.current = setTimeout(() => {
setShowMenu(false) setShowMenu(false)
},5000) },5000)
} }
function bindTimeupdateFun(e) { function bindTimeupdateFun(e) {
@ -126,17 +131,6 @@ const VideoPro:FC<Props> = ({src,onRef,showFull}) => {
} }
} }
function play(e){
e.stopPropagation();
videoContext.current.play()
setIsPlay(true)
}
function pause(){
setIsPlay(false)
videoContext.current.pause()
}
function sliderOnChange(e){ function sliderOnChange(e){
if (duration) { if (duration) {
// 视频跳转到指定位置 // 视频跳转到指定位置
@ -166,10 +160,18 @@ const VideoPro:FC<Props> = ({src,onRef,showFull}) => {
onEnded={bindEnded} onEnded={bindEnded}
onFullScreenChange={onFullScreenChange} onFullScreenChange={onFullScreenChange}
> >
<View onTouchStart={onTouchStart} onTouchEnd={onTouchEnd} style={{width:isFull?`${globalData.screenHeight}px`:'750rpx',height:isFull?'750rpx':'600rpx',display:'flex',flexDirection:'column',boxSizing:'border-box',paddingLeft:isFull?`${globalData.statusBarHeight}px`:'0',paddingRight:isFull?`${globalData.statusBarHeight}px`:'0'}}> <View className="control" onTouchStart={onTouchStart} onTouchEnd={onTouchEnd} style={{
<View onClick={pause} className="justify-center align-center flex pt-5" style={{flex:'1',boxSizing:'border-box'}}> width:isFull?`${globalData.screenHeight}px`:'750rpx',
height:isFull?'750rpx':'600rpx',
paddingLeft:isFull?`${globalData.statusBarHeight}px`:'0',
paddingRight:isFull?`${globalData.statusBarHeight}px`:'0'
}}>
<View onClick={pause} className="justify-center align-center flex pt-5" style={{
flex:'1',
boxSizing:'border-box'
}}>
{ !isPlay && showMenu && { !isPlay && showMenu &&
<View className="flex justify-center align-center rounded-50 pl-1" style={{width:'50px',height:'50px',backgroundColor:'rgba(0,0,0,0.5)',boxSizing:'border-box'}}> <View className="flex justify-center align-center rounded-50 pl-1 centerBtnBg">
<Icon onClick={play} name="play" color="#fff" size="35px"></Icon> <Icon onClick={play} name="play" color="#fff" size="35px"></Icon>
</View> </View>
} }
@ -189,8 +191,8 @@ const VideoPro:FC<Props> = ({src,onRef,showFull}) => {
<Text className="text-white font-26 pr-2">{total_duration}</Text> <Text className="text-white font-26 pr-2">{total_duration}</Text>
{ showFull && { showFull &&
<> <>
{isFull? <Image style={{width:'25px',height:'25px'}} onClick={() => {videoContext.current.exitFullScreen()}} src={unfull} /> {isFull? <Image style={{width:'25px',height:'25px'}} onClick={() => videoContext.current.exitFullScreen()} src={unfull} />
: <Image style={{width:'23px',height:'23px'}} src={full} onClick={() => {videoContext.current.requestFullScreen({direction:90})}} />} : <Image style={{width:'23px',height:'23px'}} src={full} onClick={() => videoContext.current.requestFullScreen({direction:90})} />}
</> </>
} }
</> </>

Loading…
Cancel
Save