master
lgf 3 years ago
parent 287fb81342
commit 13b04e0212
  1. 10
      src/appComponent.tsx
  2. 17
      src/core/context/index.ts
  3. 3
      src/core/controller/index.tsx
  4. 1
      src/core/progress/index.tsx
  5. 18
      src/core/useVideo.ts

@ -5,7 +5,6 @@ import '@/icons/';
const AppComponent = memo(function AppComponent(props) { const AppComponent = memo(function AppComponent(props) {
const videoRef = useRef<HTMLVideoElement>(null!); const videoRef = useRef<HTMLVideoElement>(null!);
const xx = useRef(false); const xx = useRef(false);
useEffect(() => {}, [videoRef.current]);
const { isPlay, handleChangePlayState, currentTime } = useVideo({ const { isPlay, handleChangePlayState, currentTime } = useVideo({
videoElement: videoElement:
videoRef.current && videoRef.current &&
@ -16,12 +15,15 @@ const AppComponent = memo(function AppComponent(props) {
// onPlay: (val: any) => { // onPlay: (val: any) => {
// console.log(val, xx.current); // console.log(val, xx.current);
// }, // },
onTimeChange: (val: any) => { // onTimeChange: (val: any) => {
console.log(val); // console.log(val);
}, // },
// onEndEd: (val: any) => { // onEndEd: (val: any) => {
// console.log('结束', val); // console.log('结束', val);
// }, // },
onProgressSlide(val: any) {
console.log(`童东风`, val);
},
}); });
return ( return (

@ -13,6 +13,10 @@ export interface VideoStateType<K = boolean, T = number> {
* @description * @description
*/ */
isPlay: K; isPlay: K;
/**
* @description onProgressSlider事件的变化数据onProgressSlider事件触发的
*/
progressSliderChangeVal: T;
} }
/** /**
* @description * @description
@ -31,6 +35,7 @@ export const initialState = {
isControl: false, isControl: false,
currentTime: 0, currentTime: 0,
isPlay: false, isPlay: false,
progressSliderChangeVal: 0,
}; };
export const defaultValue = { export const defaultValue = {
@ -53,7 +58,15 @@ export interface isPlayActionType {
type: 'isPlay'; type: 'isPlay';
data: VideoStateType['isPlay']; data: VideoStateType['isPlay'];
} }
export type mergeAction = isControlActionType | currentTimeActionType | isPlayActionType; export interface progressSliderChangeValActionType {
type: 'progressSliderChangeVal';
data: VideoStateType['progressSliderChangeVal'];
}
export type mergeAction =
| isControlActionType
| currentTimeActionType
| isPlayActionType
| progressSliderChangeValActionType;
export const useVideoFlow = () => { export const useVideoFlow = () => {
const reducer = (state: VideoStateType, action: mergeAction) => { const reducer = (state: VideoStateType, action: mergeAction) => {
@ -64,6 +77,8 @@ export const useVideoFlow = () => {
return { ...state, currentTime: action.data }; return { ...state, currentTime: action.data };
case 'isPlay': case 'isPlay':
return { ...state, isPlay: action.data }; return { ...state, isPlay: action.data };
case 'progressSliderChangeVal':
return { ...state, progressSliderChangeVal: action.data };
default: default:
return state; return state;
} }

@ -29,6 +29,9 @@ const Index = memo(function Index(props) {
// onEndEd: (val: any) => { // onEndEd: (val: any) => {
// console.log('结束', val); // console.log('结束', val);
// }, // },
// onProgressSlide: (val: any) => {
// console.log(`童东风`, val);
// },
}); });
const timer = useRef<NodeJS.Timeout | null>(null!); const timer = useRef<NodeJS.Timeout | null>(null!);

@ -128,6 +128,7 @@ const Index = memo(function Index(props) {
const seekPositionX = const seekPositionX =
clientXdistance.current - progressSeekMaskRef.current.getBoundingClientRect().left + 1; clientXdistance.current - progressSeekMaskRef.current.getBoundingClientRect().left + 1;
updateCurrentTime(seekPositionX, progressSeekMaskRefOffsetWidth); updateCurrentTime(seekPositionX, progressSeekMaskRefOffsetWidth);
reviceProps.dispatch!({ type: 'progressSliderChangeVal', data: Date.now() });
}, 1); }, 1);
}; };
/** /**

@ -3,7 +3,7 @@ import useMandatoryUpdate from '@/utils/useMandatoryUpdate';
import { FlowContext } from '@/core/context'; import { FlowContext } from '@/core/context';
export const useVideo = ( export const useVideo = (
{ videoElement, onPause, onPlay, onTimeChange, onEndEd }: any, { videoElement, onPause, onPlay, onTimeChange, onEndEd, onProgressSlide }: any,
dep?: any, dep?: any,
) => { ) => {
const forceUpdate = useMandatoryUpdate(); const forceUpdate = useMandatoryUpdate();
@ -63,7 +63,6 @@ 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,
@ -81,6 +80,20 @@ export const useVideo = (
}; };
}, [videoRef.current, dep, videoElement]); }, [videoRef.current, dep, videoElement]);
const ProgressSlideChange = useCallback(
(onProgressSlide: any) => {
// console.log(`onProgressSlide`, onProgressSlide);
onProgressSlide && onProgressSlide(videoParameter.current);
},
[videoFlow.progressSliderChangeVal],
);
useEffect(() => {
if (videoFlow.progressSliderChangeVal) {
ProgressSlideChange(onProgressSlide);
}
}, [ProgressSlideChange]);
const torture = (val: any) => { const torture = (val: any) => {
videoParameter.current = { ...videoParameter.current, ...val }; videoParameter.current = { ...videoParameter.current, ...val };
}; };
@ -106,6 +119,7 @@ export const useVideo = (
videoRef.current.play(); videoRef.current.play();
} }
}; };
return useMemo( return useMemo(
() => ({ () => ({
handleChangePlayState, handleChangePlayState,

Loading…
Cancel
Save