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

Commit 2dcead1

Browse files
authored
Merge pull request #8 from alantoa/feature/control-props
Add a couple of video playing props for greater control and manipulation of video playing
2 parents 83ce48c + 39538be commit 2dcead1

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,4 +302,25 @@ The `<VideoPlayer/>` component has the following configuration properties:
302302
<td>❌</td>
303303
<td>undefined</td>
304304
</tr>
305+
<tr>
306+
<td>children</td>
307+
<td>JSX</td>
308+
<td>child components to be rendered under video player controls</td>
309+
<td>❌</td>
310+
<td>undefined</td>
311+
</tr>
312+
<tr>
313+
<td>onPostProgress</td>
314+
<td>function</td>
315+
<td>callback function that is called every progressUpdateInterval milliseconds with info about which position the media is currently playing</td>
316+
<td>❌</td>
317+
<td>undefined
318+
</tr>
319+
<tr>
320+
<td>onPostSeek</td>
321+
<td>function</td>
322+
<td>callback function that is called when a seek completes</td>
323+
<td>❌</td>
324+
<td>undefined
325+
</tr>
305326
</table>

example/src/screens/video.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,8 @@ export const VideoScreen = ({
569569
resizeMode="cover"
570570
isFullScreen={isFullScreen}
571571
disableControl={diasbled}
572+
onPostProgress={() => console.log('onProgress')}
573+
onPostSeek={() => console.log('onSeek')}
572574
renderBackIcon={() => (
573575
<Icon
574576
name="a-ic_chevrondown_16"

src/index.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ export type VideoProps = VideoProperties & {
9595
onVideoPlayEnd?: () => void;
9696
onAutoPlayText?: string;
9797
offAutoPlayText?: string;
98+
children?: any;
99+
onPostProgress?: (data: OnProgressData) => void;
100+
onPostSeek?: (data: OnSeekData) => void;
98101
};
99102
export type VideoPlayerRef = {
100103
/**
@@ -160,6 +163,9 @@ const VideoPlayer = forwardRef<VideoPlayerRef, VideoProps>(
160163
onVideoPlayEnd,
161164
onAutoPlayText = 'Autoplay is on',
162165
offAutoPlayText = 'Autoplay is off',
166+
children,
167+
onPostProgress,
168+
onPostSeek,
163169
...rest
164170
},
165171
ref,
@@ -677,6 +683,9 @@ const VideoPlayer = forwardRef<VideoPlayerRef, VideoProps>(
677683
} else {
678684
isSeeking.current = false;
679685
}
686+
if (onPostSeek) {
687+
onPostSeek(data);
688+
}
680689
};
681690

682691
/**
@@ -685,13 +694,17 @@ const VideoPlayer = forwardRef<VideoPlayerRef, VideoProps>(
685694
*
686695
* @param {object} data The video meta data
687696
*/
688-
const onProgress = ({ currentTime: cTime }: OnProgressData) => {
697+
const onProgress = (data: OnProgressData) => {
698+
const { currentTime: cTime } = data;
689699
if (!isScrubbing.value) {
690700
if (!isSeeking.current) {
691701
progress.value = cTime;
692702
}
693703
setCurrentTime(cTime);
694704
}
705+
if (onPostProgress) {
706+
onPostProgress(data);
707+
}
695708
};
696709
/**
697710
* on replay video
@@ -838,6 +851,7 @@ const VideoPlayer = forwardRef<VideoPlayerRef, VideoProps>(
838851
onProgress={onProgress}
839852
fullscreenAutorotate={true}
840853
/>
854+
{Boolean(children) && children}
841855
<VideoLoader loading={loading} />
842856
<Animated.View style={StyleSheet.absoluteFillObject}>
843857
<Animated.View style={[styles.controlView, controlViewStyles]}>

0 commit comments

Comments
 (0)