Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

Commit

Permalink
feat: add onPostProgress, onPostSeek and children props
Browse files Browse the repository at this point in the history
  • Loading branch information
khlling committed Aug 19, 2022
1 parent 83ce48c commit 39538be
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -302,4 +302,25 @@ The `<VideoPlayer/>` component has the following configuration properties:
<td>❌</td>
<td>undefined</td>
</tr>
<tr>
<td>children</td>
<td>JSX</td>
<td>child components to be rendered under video player controls</td>
<td>❌</td>
<td>undefined</td>
</tr>
<tr>
<td>onPostProgress</td>
<td>function</td>
<td>callback function that is called every progressUpdateInterval milliseconds with info about which position the media is currently playing</td>
<td>❌</td>
<td>undefined
</tr>
<tr>
<td>onPostSeek</td>
<td>function</td>
<td>callback function that is called when a seek completes</td>
<td>❌</td>
<td>undefined
</tr>
</table>
2 changes: 2 additions & 0 deletions example/src/screens/video.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,8 @@ export const VideoScreen = ({
resizeMode="cover"
isFullScreen={isFullScreen}
disableControl={diasbled}
onPostProgress={() => console.log('onProgress')}
onPostSeek={() => console.log('onSeek')}
renderBackIcon={() => (
<Icon
name="a-ic_chevrondown_16"
Expand Down
16 changes: 15 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ export type VideoProps = VideoProperties & {
onVideoPlayEnd?: () => void;
onAutoPlayText?: string;
offAutoPlayText?: string;
children?: any;
onPostProgress?: (data: OnProgressData) => void;
onPostSeek?: (data: OnSeekData) => void;
};
export type VideoPlayerRef = {
/**
Expand Down Expand Up @@ -160,6 +163,9 @@ const VideoPlayer = forwardRef<VideoPlayerRef, VideoProps>(
onVideoPlayEnd,
onAutoPlayText = 'Autoplay is on',
offAutoPlayText = 'Autoplay is off',
children,
onPostProgress,
onPostSeek,
...rest
},
ref,
Expand Down Expand Up @@ -677,6 +683,9 @@ const VideoPlayer = forwardRef<VideoPlayerRef, VideoProps>(
} else {
isSeeking.current = false;
}
if (onPostSeek) {
onPostSeek(data);
}
};

/**
Expand All @@ -685,13 +694,17 @@ const VideoPlayer = forwardRef<VideoPlayerRef, VideoProps>(
*
* @param {object} data The video meta data
*/
const onProgress = ({ currentTime: cTime }: OnProgressData) => {
const onProgress = (data: OnProgressData) => {
const { currentTime: cTime } = data;
if (!isScrubbing.value) {
if (!isSeeking.current) {
progress.value = cTime;
}
setCurrentTime(cTime);
}
if (onPostProgress) {
onPostProgress(data);
}
};
/**
* on replay video
Expand Down Expand Up @@ -838,6 +851,7 @@ const VideoPlayer = forwardRef<VideoPlayerRef, VideoProps>(
onProgress={onProgress}
fullscreenAutorotate={true}
/>
{Boolean(children) && children}
<VideoLoader loading={loading} />
<Animated.View style={StyleSheet.absoluteFillObject}>
<Animated.View style={[styles.controlView, controlViewStyles]}>
Expand Down

0 comments on commit 39538be

Please sign in to comment.