useAdaptiveVideoEnabled()
useAdaptiveVideoEnabled():
boolean
Returns whether adaptive video playback (ABR) is currently enabled.
This hook provides a reactive way to observe and respond to changes in the player’s adaptive video mode — i.e., whether the player automatically selects the optimal video rendition based on current network and performance conditions.
Disabling ABR: There is no disableAdaptiveVideo(). To turn off adaptive playback,
select a specific rendition with player.getTrackManager().setVideoRendition(rendition),
which automatically disables ABR. To re-enable ABR, call
player.getTrackManager().enableAdaptiveVideo().
⚠️ Must be used within a PlayerProvider or AVPlayerViewControllerProvider component.
Returns
boolean
boolean true if adaptive (ABR) mode is enabled, otherwise false.
Example
import React from 'react';
import { View, Text, Button } from 'react-native';
import {
usePlayer,
useAdaptiveVideoEnabled,
useVideoRenditions,
} from '@castlabs/react-native-prestoplay';
export default function AdaptivePlaybackControl() {
const player = usePlayer();
const adaptiveEnabled = useAdaptiveVideoEnabled();
const renditions = useVideoRenditions();
// Re-enable adaptive playback (ABR)
const enableAdaptive = async () => {
await player.getTrackManager().enableAdaptiveVideo();
};
// Disable ABR by locking to the currently active rendition
const lockToCurrentQuality = async () => {
const current = renditions.find(r => r.active) ?? renditions[0];
if (current) {
await player.getTrackManager().setVideoRendition(current);
}
};
return (
<View>
<Text>Adaptive Playback: {adaptiveEnabled ? 'Enabled' : 'Disabled'}</Text>
{adaptiveEnabled ? (
<Button title="Lock to Current Quality" onPress={lockToCurrentQuality} />
) : (
<Button title="Enable Adaptive Playback" onPress={enableAdaptive} />
)}
</View>
);
}