Volume
Volume level and mute state for the player store
Controls volume level and mute state. These capabilities have independent availability values because media can support mute without supporting volume-level changes.
Import
import { volumeFeature } from '@videojs/react';import { volumeFeature } from '@videojs/html';The audioFeatures, liveAudioFeatures, liveVideoFeatures, and videoFeatures feature bundles include this feature.
API Reference
State
| Property | Type | Details |
|---|---|---|
volume | number | |
| ||
muted | boolean | |
| ||
volumeAvailability | 'available' | 'unavailable' | 'unsupported' | |
| ||
mutedAvailability | 'available' | 'unavailable' | 'unsupported' | |
| ||
Actions
| Action | Type | Details |
|---|---|---|
setVolume | (volume: number) => number | |
| ||
toggleMuted | () => boolean | |
| ||
Selector
Pass selectVolume to usePlayer to subscribe to volume state. Returns undefined if the volume feature is not configured.
Check volumeAvailability before showing a volume-level control, and check mutedAvailability before showing a mute control.
Pass selectVolume to PlayerController to subscribe to volume state. Returns undefined if the volume feature is not configured.
Check volumeAvailability before showing a volume-level control, and check mutedAvailability before showing a mute control.
import { selectVolume, usePlayer } from '@videojs/react';
function VolumeSlider() {
const vol = usePlayer(selectVolume);
if (!vol || vol.volumeAvailability !== 'available') return null;
return (
<input
type="range"
min={0}
max={1}
step={0.01}
value={vol.volume}
onChange={(e) => vol.setVolume(Number(e.target.value))}
/>
);
}import { createPlayer, UIElement, selectVolume } from '@videojs/html';
import { videoFeatures } from '@videojs/html/video';
const { PlayerController } = createPlayer({ features: videoFeatures });
class VolumeSlider extends UIElement {
readonly #volume = new PlayerController(this, selectVolume);
}