Skip to main content

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).

Deprecated​

When combined with usePosition to derive a value from both fields (e.g. a live wall-clock position via liveStartTime + position), the two hooks can momentarily expose a torn pair during the render between their independent state updates — visible on LIVE when the DVR window slides, causing the derived position to briefly jump backwards. Use usePositionInfo when you need both values together.

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>
);
}