Limeplay - Open Source Video Player UI ComponentsLimeplay

Playback Control

Controls the play/pause state of the Media.

Installation

Install the component

npx shadcn add @limeplay/playback-control

Add Event & Action Bridge

Import the useMediaStates hook in your existing PlayerHooks component.

components/limeplay/player-hooks.tsx
"use client"

import React from "react"

import { usePlayerStates } from "@/hooks/limeplay/use-player"
import { useShakaPlayer } from "@/hooks/limeplay/use-shaka-player"

export const PlayerHooks = React.memo(() => {
  useShakaPlayer()
  usePlayerStates() 

  return null
})

Add the Store States

lib/create-media-store.ts
import { createPlayerStore, PlayerStore } from "@/hooks/limeplay/use-player"


export type TypeMediaStore = PlayerStore & {} 

export function createMediaStore(initProps?: Partial<CreateMediaStoreProps>) {
  const mediaStore = create<TypeMediaStore>()((...etc) => ({
    ...createPlayerStore(...etc),
    ...initProps,
  }))
  return mediaStore
}

Example Usage

  1. Design the playback button with icons and states.
components/player/playback-control-button.tsx
import { PauseIcon, PlayIcon } from "@phosphor-icons/react"

import { Button } from "@/components/ui/button"
import { useMediaStore } from "@/components/limeplay/media-provider"
import { PlaybackControl } from "@/components/limeplay/playback-control"

export function PlaybackControlButton() {
  const status = useMediaStore((state) => state.status)

  return (
    <PlaybackControl asChild>
      <Button variant="ghost" size="icon">
        {status === "playing" ? (
          <PauseIcon weight="fill" size={18} />
        ) : (
          <PlayIcon weight="fill" size={18} />
        )}
      </Button>
    </PlaybackControl>
  )
}
  1. Use the component in your player.
components/player/bottom-controls.tsx
<PlaybackControlButton />

Understanding

The PlaybackControl component uses the usePlayer() hook to control playback state. You can use the status field from media store to get the current status of the media. List of possible values are:

StatusDescription
playingThe media is playing
pausedThe media is paused
endedThe media has reached the end
bufferingThe media is buffering
errorThe media has encountered an error
initThe media is initializing or has readyState 0
stoppedThe media has been stopped

The PlaybackControl component automatically handles all these states and shows appropriate behavior (e.g., "Replay" for ended state).

Components

PlaybackControl

The main component for toggling play/pause state. It supports the Slot pattern (asChild prop) for composition.

API Reference

Prop

Type

On this page