ComponentsDisplay
TimeDisplay
A control component that displays the current playback time and/or total duration of the video.
Usage
Default (Both)
0:00
/
0:00
Current Time Only
0:00
Duration Only
0:00
import { Card, CardHeader, CardContent } from '@/components/ui/card';
import React, { useEffect } from 'react';
import { View, StyleSheet } from 'react-native';
import { TimeDisplay, useProgress } from 'react-native-video-toolkit';
interface TimeDisplayDemoProps {
title: string;
type?: 'current' | 'duration' | 'both';
}
const TimeDisplayDemo = ({ title, type }: TimeDisplayDemoProps) => {
return (
<Card className="flex-1 min-w-[200px]">
<CardHeader className="pb-3">
<p className="text-sm font-medium text-muted-foreground">{title}</p>
</CardHeader>
<CardContent className="pt-0">
<TimeDisplay type={type} />
</CardContent>
</Card>
);
};
export const TimeDisplayExample = () => {
const { setDuration, setCurrentTime } = useProgress();
useEffect(() => {
setDuration(300); // Set total duration to 5 minutes
setCurrentTime(120); // Set current time to 2 minutes
}, [setDuration, setCurrentTime]);
return (
<View style={styles.container}>
<TimeDisplayDemo title="Default (Both)" />
<TimeDisplayDemo title="Current Time Only" type="current" />
<TimeDisplayDemo title="Duration Only" type="duration" />
</View>
);
};
const styles = StyleSheet.create({
container: {
gap: 12,
maxWidth: 800,
flexDirection: 'row',
flexWrap: 'wrap',
alignItems: 'flex-start',
},
});Props
| Prop | Type | Required | Default | Description |
|---|---|---|---|---|
type | 'current' | 'duration' | 'both' | No | 'both' | What time information to display. |
fontSize | number | No | 14 | Font size of the time text. |
color | string | No | theme.colors.text | Text color. Falls back to the current theme if not provided. |
style | StyleProp<ViewStyle> | No | – | Custom style for the container. |
Examples
Show Current Time Only
<TimeDisplay type="current" /> // e.g. "0:15"Show Duration Only
<TimeDisplay type="duration" /> // e.g. "3:45"Show Both Current Time and Duration
<TimeDisplay type="both" /> // e.g. "0:15 / 3:45"Integration Example
TimeDisplay is typically used inside the VideoPlayer as part of your controls:
import { VideoPlayer, TimeDisplay } from 'react-native-video-toolkit';
const MyVideoPlayer = () => {
return (
<VideoPlayer source={{ uri: 'https://example.com/video.mp4' }}>
<VideoPlayer.Controls>
<TimeDisplay type="both" fontSize={16} />
</VideoPlayer.Controls>
</VideoPlayer>
);
};- If you don't pass a
color,TimeDisplayautomatically usestheme.colors.textfrom the current video context. - Works seamlessly with custom layouts and pre-built controls.