usePositionInfo()
usePositionInfo():
PositionInfo
Returns the player’s current position and live start time together as a single, always-consistent snapshot.
Both values originate from the same PositionChanged event. Reading them through
separate hooks (usePosition + useLiveStartTime) can momentarily expose
a torn pair — the new position with a stale liveStartTime (or vice versa) — during
the render in between their independent state updates. This is visible on LIVE streams
whenever the DVR window slides: liveStartTime + position can briefly jump backwards.
usePositionInfo stores both fields in a single state cell updated from one listener,
so the pair always moves together. Prefer it whenever you derive a value from both
fields, such as a live wall-clock position (liveStartTime + position).
- Update frequency: Fired at most once per second.
- VOD:
positionis in the range [0, duration];liveStartTimeisnull. - LIVE:
positionis an offset in ms from the live content start (DVR window origin), not an absolute wall-clock timestamp.
⚠️ Must be used within a PlayerProvider or AVPlayerViewControllerProvider component.
Returns
PositionInfo with the current position and liveStartTime.
Example
import { usePositionInfo } from '@castlabs/react-native-prestoplay';
function LivePosition() {
const { position, liveStartTime } = usePositionInfo();
// Always consistent, even while the live window slides:
const wallClock = (liveStartTime ?? 0) + position;
return <Text>{new Date(wallClock).toLocaleTimeString()}</Text>;
}