usePlaybackStats()
usePlaybackStats():
null|PlaybackStats
Returns the latest playback statistics from the player.
This hook provides a reactive way to monitor low-level playback metrics such as bitrate, dropped frames, buffer length, and other statistics related to playback performance and quality.
Platform behavior
- Android: Updates are emitted every second.
- iOS / tvOS: Updates are emitted only when the statistics change.
Typical use cases include displaying metrics in a developer overlay, tracking playback health for monitoring tools, or adapting UI based on quality indicators.
⚠️ Must be used within a PlayerProvider or AVPlayerViewControllerProvider component.
Returns
null | PlaybackStats
{PlaybackStats | null} The most recent playback statistics, or null if unavailable.
Example
import React from 'react';
import { View, Text } from 'react-native';
import { usePlaybackStats } from '@castlabs/react-native-prestoplay';
export default function PlaybackStatsDisplay() {
const stats = usePlaybackStats();
if (!stats) return <Text>No playback stats available.</Text>;
return (
<View>
<Text>Bitrate: {stats.streamBandwidth} bps</Text>
<Text>Estimated Bandwidth: {stats.estimatedBandwidth} bps</Text>
<Text>Dropped Frames: {stats.droppedFrames}</Text>
</View>
);
}