parent
38f9458ff3
commit
eb5b02f4c2
11 changed files with 234 additions and 112 deletions
@ -1,35 +1,68 @@ |
||||
import { useEffect } from 'react'; |
||||
import { videoAttributes, videoCallback } from '@/interface'; |
||||
import { VideoStateType } from './context'; |
||||
|
||||
const useVideoCallback = (videoPr: any, videoFlow: any, handle: any) => { |
||||
const { isPlay, currentTime, isEndEd } = videoPr; |
||||
const { progressSliderChangeVal } = videoFlow; |
||||
const { onProgressSlide, onPlay, onPause, onTimeChange, onEndEd } = handle; |
||||
const useVideoCallback = ( |
||||
videoPr: videoAttributes, |
||||
videoFlow: VideoStateType, |
||||
handle: Partial<videoCallback>, |
||||
) => { |
||||
const { isPlay, currentTime, isEndEd, error, volume } = videoPr; |
||||
const { progressSliderChangeVal, progressMouseUpChangeVal } = videoFlow; |
||||
const { |
||||
onProgressMouseDown, |
||||
onPlay, |
||||
onPause, |
||||
onTimeChange, |
||||
onEndEd, |
||||
onProgressMouseUp, |
||||
onError, |
||||
onvolumechange, |
||||
} = handle; |
||||
|
||||
useEffect(() => { |
||||
if (videoFlow.progressSliderChangeVal) { |
||||
onProgressSlide && onProgressSlide(progressSliderChangeVal); |
||||
onProgressMouseDown && onProgressMouseDown(videoPr); |
||||
} |
||||
}, [progressSliderChangeVal]); |
||||
|
||||
useEffect(() => { |
||||
if (videoFlow.progressMouseUpChangeVal) { |
||||
onProgressMouseUp && onProgressMouseUp(videoPr); |
||||
} |
||||
}, [progressMouseUpChangeVal]); |
||||
|
||||
useEffect(() => { |
||||
if (isPlay) { |
||||
onPlay && onPlay(isPlay); |
||||
onPlay && onPlay(videoPr); |
||||
} else { |
||||
onPause && onPause(isPlay); |
||||
onPause && onPause(videoPr); |
||||
} |
||||
}, [isPlay]); |
||||
|
||||
useEffect(() => { |
||||
if (currentTime) { |
||||
onTimeChange && onTimeChange(currentTime); |
||||
onTimeChange && onTimeChange(videoPr); |
||||
} |
||||
}, [currentTime]); |
||||
|
||||
useEffect(() => { |
||||
if (isEndEd) { |
||||
onEndEd && onEndEd(isEndEd); |
||||
onEndEd && onEndEd(videoPr); |
||||
} |
||||
}, [isEndEd]); |
||||
|
||||
useEffect(() => { |
||||
if (error) { |
||||
onError && onError(); |
||||
} |
||||
}, [error]); |
||||
|
||||
useEffect(() => { |
||||
if (volume) { |
||||
onvolumechange && onvolumechange(videoPr); |
||||
} |
||||
}, [volume]); |
||||
}; |
||||
|
||||
export default useVideoCallback; |
||||
|
Loading…
Reference in new issue