useLiveStartTime()
useLiveStartTime():
null|number
Returns the live start time in milliseconds since the Unix epoch.
This hook provides a reactive way to observe and respond to changes in the live stream’s start time, as reported by the manifest. This is typically used to calculate absolute playback positions or to display timestamps in live and DVR playback UIs.
A live HLS stream must include the EXT-X-PROGRAM-DATE-TIME tag for this value
to be available.
Platform behavior
- HLS: Supported on both Android and iOS.
- DASH: Not available on iOS (value will always be
null).
⚠️ Must be used within a PlayerProvider or AVPlayerViewControllerProvider component.
Returns
null | number
{number | null} The live start time in milliseconds since the epoch, or null
if unavailable or not applicable (e.g., VOD playback).
Example
import React from 'react';
import { View, Text } from 'react-native';
import {
useLive,
useLiveStartTime,
usePosition,
} from '@castlabs/react-native-prestoplay';
export default function LiveTimeDisplay() {
const isLive = useLive();
const liveStartTime = useLiveStartTime();
const position = usePosition();
if (!isLive || !liveStartTime) {
return <Text>Not a live stream</Text>;
}
const wallClockTime = new Date(liveStartTime + position).toLocaleTimeString();
return (
<View>
<Text>Live start: {new Date(liveStartTime).toLocaleTimeString()}</Text>
<Text>Current time: {wallClockTime}</Text>
</View>
);
}