Skip to content

usePlayer

Controls the timeline and playback engine. Used to play, stop, and seek through animations and video/audio items.

Import

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

Usage

tsx
function PlaybackControls() {
  const { play, stop, isPlaying, currentTime, onSeekStart, onSeek, onSeekEnd } = usePlayer()

  return (
    <div>
      <button onClick={isPlaying ? stop : play}>
        {isPlaying ? 'Stop' : 'Play'}
      </button>
      <input
        type="range"
        min={0}
        value={currentTime}
        onMouseDown={onSeekStart}
        onChange={e => onSeek(Number(e.target.value))}
        onMouseUp={onSeekEnd}
      />
    </div>
  )
}

Return Value

Property / FunctionTypeDescription
isPlayingbooleanWhether the timeline is currently playing.
isVideobooleanWhether the canvas contains video items.
currentTimenumberCurrent playback position in milliseconds.
play() => voidStart playback from the current position.
stop() => voidStop playback.
onSeekStart() => voidCall when the user begins scrubbing (e.g. onMouseDown).
onSeek(timeMs: number) => voidCall as the user scrubs to update the current time.
onSeekEnd() => voidCall when the user finishes scrubbing (e.g. onMouseUp).

Notes

  • The player controls both animation timings and video/audio playback simultaneously.
  • Use onSeekStart, onSeek, and onSeekEnd together when building a scrubber — splitting the events prevents conflicts with active playback.

Released under a proprietary license.