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

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

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

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

@ -3,7 +3,7 @@ import useMandatoryUpdate from '@/utils/useMandatoryUpdate';
import { FlowContext } from '@/core/context';
export const useVideo = (
{ videoElement, onPause, onPlay, onTimeChange, onEndEd }: any,
{ videoElement, onPause, onPlay, onTimeChange, onEndEd, onProgressSlide }: any,
dep?: any,
) => {
const forceUpdate = useMandatoryUpdate();
@ -63,7 +63,6 @@ export const useVideo = (
*
*/
forceUpdate();
torture({
currentTime: videoRef.current.currentTime,
isPlay: videoRef.current.paused ? false : true,
@ -81,6 +80,20 @@ export const useVideo = (
};
}, [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) => {
videoParameter.current = { ...videoParameter.current, ...val };
};
@ -106,6 +119,7 @@ export const useVideo = (
videoRef.current.play();
}
};
return useMemo(
() => ({
handleChangePlayState,

Loading…
Cancel
Save