Skip to content

PlayerProvider

Manages playback state for compositions that contain video, audio, or animations. Wrap Asset with PlayerProvider when you need playback controls.

Usage

tsx
import { SessionProvider, PlayerProvider, Asset } from '@asset-studio/core'

export default function App() {
  return (
    <SessionProvider onCreateSession={createSession}>
      <PlayerProvider>
        <PlaybackControls />
        <Asset items={items} width={1920} height={1080} />
      </PlayerProvider>
    </SessionProvider>
  )
}

Props

PropTypeRequiredDescription
childrenReactNodeYesComponents that need access to playback state.

usePlayer

Control and observe playback from any component inside PlayerProvider:

tsx
import { usePlayer } from '@asset-studio/core'

function PlaybackControls() {
  const { isPlaying, play, stop, currentTime } = usePlayer()

  return (
    <div>
      <button onClick={isPlaying ? stop : play}>
        {isPlaying ? 'Stop' : 'Play'}
      </button>
      <span>{currentTime}ms</span>
    </div>
  )
}

Return Value

PropertyTypeDescription
isPlayingbooleanWhether playback is currently active.
play() => voidStart playback.
stop() => voidStop and reset playback to the beginning.
currentTimenumberCurrent playback position in milliseconds.
isVideobooleanWhether the composition contains video, audio, or animations.
onSeekStart() => voidCall when a seek interaction begins (e.g. scrubber mousedown).
onSeek(timeMs: number) => voidCall during seeking to update the current time.
onSeekEnd() => voidCall when a seek interaction ends (e.g. scrubber mouseup).

Released under a proprietary license.