|
|
@ -1,11 +1,13 @@ |
|
|
|
import { useRef, useMemo, useEffect, useState, useReducer, useContext, useCallback } from 'react'; |
|
|
|
import { useRef, useMemo, useEffect, useState, useReducer, useContext, useCallback } from 'react'; |
|
|
|
import useMandatoryUpdate from '@/utils/useMandatoryUpdate'; |
|
|
|
import useMandatoryUpdate from '@/utils/useMandatoryUpdate'; |
|
|
|
import { FlowContext } from '@/core/context'; |
|
|
|
import { FlowContext } from '@/core/context'; |
|
|
|
|
|
|
|
import useWindowClient from '@/utils/useWindowClient'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const useVideo = (props: any, dep: any[] = []) => { |
|
|
|
|
|
|
|
const { clientX } = useWindowClient(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const { videoElement, onPause, onPlay, onTimeChange, onEndEd, onProgressSlide } = props; |
|
|
|
|
|
|
|
|
|
|
|
export const useVideo = ( |
|
|
|
|
|
|
|
{ videoElement, onPause, onPlay, onTimeChange, onEndEd, onProgressSlide }: any, |
|
|
|
|
|
|
|
dep?: any, |
|
|
|
|
|
|
|
) => { |
|
|
|
|
|
|
|
const forceUpdate = useMandatoryUpdate(); |
|
|
|
const forceUpdate = useMandatoryUpdate(); |
|
|
|
|
|
|
|
|
|
|
|
const reviceProps = useContext(FlowContext); |
|
|
|
const reviceProps = useContext(FlowContext); |
|
|
@ -29,7 +31,10 @@ export const useVideo = ( |
|
|
|
videoRef.current = videoElement; |
|
|
|
videoRef.current = videoElement; |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
forceUpdate(); |
|
|
|
/** |
|
|
|
|
|
|
|
* @description 防止在外部组件用,不更新的问题,所以要强制更新 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
// forceUpdate();
|
|
|
|
if (videoRef.current) { |
|
|
|
if (videoRef.current) { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* @description 监听总时长 |
|
|
|
* @description 监听总时长 |
|
|
@ -62,7 +67,7 @@ export const useVideo = ( |
|
|
|
/** |
|
|
|
/** |
|
|
|
* 强制更新 |
|
|
|
* 强制更新 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
forceUpdate(); |
|
|
|
// forceUpdate();
|
|
|
|
torture({ |
|
|
|
torture({ |
|
|
|
currentTime: videoRef.current.currentTime, |
|
|
|
currentTime: videoRef.current.currentTime, |
|
|
|
isPlay: videoRef.current.paused ? false : true, |
|
|
|
isPlay: videoRef.current.paused ? false : true, |
|
|
@ -78,11 +83,11 @@ export const useVideo = ( |
|
|
|
return () => { |
|
|
|
return () => { |
|
|
|
interval.current && clearInterval(interval.current); |
|
|
|
interval.current && clearInterval(interval.current); |
|
|
|
}; |
|
|
|
}; |
|
|
|
}, [videoRef.current, dep, videoElement]); |
|
|
|
}, dep); |
|
|
|
|
|
|
|
|
|
|
|
const ProgressSlideChange = useCallback( |
|
|
|
const ProgressSlideChange = useCallback( |
|
|
|
(onProgressSlide: any) => { |
|
|
|
(onProgressSlide: any) => { |
|
|
|
// console.log(`onProgressSlide`, onProgressSlide);
|
|
|
|
console.log(`onProgressSlide`, onProgressSlide, videoFlow.progressSliderChangeVal); |
|
|
|
onProgressSlide && onProgressSlide(videoParameter.current); |
|
|
|
onProgressSlide && onProgressSlide(videoParameter.current); |
|
|
|
}, |
|
|
|
}, |
|
|
|
[videoFlow.progressSliderChangeVal], |
|
|
|
[videoFlow.progressSliderChangeVal], |
|
|
@ -92,7 +97,7 @@ export const useVideo = ( |
|
|
|
if (videoFlow.progressSliderChangeVal) { |
|
|
|
if (videoFlow.progressSliderChangeVal) { |
|
|
|
ProgressSlideChange(onProgressSlide); |
|
|
|
ProgressSlideChange(onProgressSlide); |
|
|
|
} |
|
|
|
} |
|
|
|
}, [ProgressSlideChange]); |
|
|
|
}, [ProgressSlideChange, onProgressSlide]); |
|
|
|
|
|
|
|
|
|
|
|
const torture = (val: any) => { |
|
|
|
const torture = (val: any) => { |
|
|
|
videoParameter.current = { ...videoParameter.current, ...val }; |
|
|
|
videoParameter.current = { ...videoParameter.current, ...val }; |
|
|
|