自定义ui视频组件部修正

master
一杯沧海 1 year ago
parent 624d7cb183
commit e3ced26435
  1. 15
      src/components/videoPro/index.module.scss
  2. 61
      src/components/videoPro/index.tsx

@ -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;
}

@ -14,6 +14,18 @@ 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) // 视频长度 单位秒
@ -25,15 +37,6 @@ 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('组件加载')
@ -41,16 +44,7 @@ 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) {
@ -66,6 +60,7 @@ 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) {
@ -131,6 +126,17 @@ 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) {
// 视频跳转到指定位置 // 视频跳转到指定位置
@ -148,7 +154,6 @@ const VideoPro:FC<Props> = ({src,onRef,showFull}) => {
<Video <Video
style={{width: '750rpx', height: '600rpx'}} style={{width: '750rpx', height: '600rpx'}}
id='video' id='video'
// src={brandInfo?.introductory_video_resource?.url}
src={src} src={src}
controls={false} controls={false}
showPlayBtn={false} showPlayBtn={false}
@ -160,18 +165,10 @@ const VideoPro:FC<Props> = ({src,onRef,showFull}) => {
onEnded={bindEnded} onEnded={bindEnded}
onFullScreenChange={onFullScreenChange} onFullScreenChange={onFullScreenChange}
> >
<View className="control" onTouchStart={onTouchStart} onTouchEnd={onTouchEnd} style={{ <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'}}>
width:isFull?`${globalData.screenHeight}px`:'750rpx', <View onClick={pause} className="justify-center align-center flex pt-5" style={{flex:'1',boxSizing:'border-box'}}>
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 centerBtnBg"> <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'}}>
<Icon onClick={play} name="play" color="#fff" size="35px"></Icon> <Icon onClick={play} name="play" color="#fff" size="35px"></Icon>
</View> </View>
} }
@ -191,8 +188,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