Volume Control
Slider control to control the media volume. Composed with volume state control
Installation
Install the component
npx shadcn add @limeplay/volume-controlAdd Event & Action Bridge
Import the useVolumeStates hook in your existing PlayerHooks component.
import React from "react"
import { useShakaPlayer } from "@/hooks/limeplay/use-shaka-player"
import { useVolumeStates } from "@/hooks/limeplay/use-volume"
export const PlayerHooks = React.memo(() => {
useShakaPlayer()
useVolumeStates()
return null
})Add the Store States
import { createPlayerStore, PlayerStore } from "@/hooks/limeplay/use-player"
import { createVolumeStore, VolumeStore } from "@/hooks/limeplay/use-volume"
export type TypeMediaStore = PlayerStore & VolumeStore & {}
export function createMediaStore(initProps?: Partial<CreateMediaStoreProps>) {
const mediaStore = create<TypeMediaStore>()((...etc) => ({
...createPlayerStore(...etc),
...createVolumeStore(...etc),
...initProps,
}))
return mediaStore
}Example Usage
- Compose the volume slide and handle states
import { cn } from "@/lib/utils"
import * as VolumeSlider from "@/components/limeplay/volume-control"
export function VolumeControlSlider() {
return (
<VolumeSlider.Root
className={cn("relative h-1 focus-area -focus-area-x-2 -focus-area-y-12")}
orientation="horizontal"
>
<VolumeSlider.Track>
<VolumeSlider.Progress />
</VolumeSlider.Track>
<VolumeSlider.Thumb />
</VolumeSlider.Root>
)
}- Use the component in your player.
<VolumeControlSlider />Understanding
The Volume Control is a composable slider built with the Event & Action Bridge pattern:
- Event Bridge:
useVolumeStates()listens tovolumechangeevents and syncs volume/mute state - Action Bridge: Components use
useVolume()to callsetVolume()which controls the media element
Accessibility
- ARIA Slider Pattern: Proper
aria-valuemin,aria-valuemax,aria-valuenowattributes - Keyboard Support: Arrow keys for volume adjustment
- Screen Reader: Announces volume percentage changes
- Visual Feedback: Clear volume level indication
Components
The volume slider is composed of multiple parts for maximum flexibility.
Root
Main container with orientation support (horizontal/vertical).
API Reference
Prop
Type
Thumb
Draggable handle for volume adjustment.
API Reference
Prop
Type
Track
Visual track showing volume range. Extends SliderPrimitive.Track props.
Progress
Filled portion showing current volume. Extends SliderPrimitive.Indicator props.