Limeplay - Open Source Video Player UI ComponentsLimeplay

use-playback

Core feature for managing media playback state and controls.

Installation

npx shadcn add @limeplay/use-playback

Register the feature:

lib/media.ts
"use client"

import { playbackFeature } from "@/hooks/limeplay/use-playback"

createMediaKit({
  features: [..., playbackFeature()] as const,
})

Store

Access via usePlaybackStore(selector):

import { usePlaybackStore } from "@/hooks/limeplay/use-playback"

const status = usePlaybackStore((s) => s.status)
const paused = usePlaybackStore((s) => s.paused)
const togglePaused = usePlaybackStore((s) => s.togglePaused)

State

FieldTypeDescription
pausedbooleanWhether media is paused
endedbooleanWhether media has ended
loopbooleanWhether looping is enabled
statusMediaStatusCurrent playback status
readyStatenumberMedia ready state (0-4)
canPlaybooleanEnough data to start playback
canPlayThroughbooleanEnough data to play without buffering
errorMediaError | nullCurrent error, if any
networkStatenumberNetwork state

Actions

MethodDescription
play()Start playback (returns Promise)
pause()Pause playback
togglePaused()Toggle play/pause (returns Promise)
restart()Restart from the beginning
setLoop(loop)Enable/disable looping
toggleLoop()Toggle loop state

Events

Emits to the event system:

EventPayloadWhen
playMedia starts playing
pauseMedia is paused
endedMedia reaches the end
buffering{ isBuffering }Buffering state changes
statuschange{ status, prevStatus }Status transitions

Media Status Values

StatusDescription
initInitializing (readyState 0)
loadingLoading media data
bufferingWaiting for data
canplayReady to start playback
canplaythroughReady to play through without buffering
playingCurrently playing
pausedPaused
endedReached the end
errorError occurred
stoppedStopped

API Reference

Prop

Type

On this page