Logoreact-timeline-editor
API Reference

Transport Bar API

Complete API reference for TransportBar, useTimelinePlayer, and formatTime.

useTimelinePlayer Hook

Manages playback state and controls for a <Timeline>. Attaches engine event listeners (play, paused, setTimeByTick) on mount and cleans them up on unmount.

function useTimelinePlayer(
  ref: React.RefObject<TimelineState>,
  options?: UseTimelinePlayerOptions,
): TimelinePlayerState;

UseTimelinePlayerOptions

OptionTypeDefaultDescription
seekStepnumber5Number of seconds to jump when calling rewind() or forward().
loopUseTimelinePlayerLoop--Optional loop configuration. When provided, the hook handles the loop clock internally.

UseTimelinePlayerLoop

PropertyTypeDescription
enabledbooleanWhether the loop is active. Safe to toggle while the timeline is playing.
startnumberLoop region start time in seconds. Must be less than end.
endnumberLoop region end time in seconds. Must be greater than start.

TimelinePlayerState (Returned)

MemberTypeDescription
isPlayingbooleanWhether the timeline is currently playing. Updated automatically from engine events.
currentTimenumberCurrent playback position in seconds. Updated on every engine tick — suitable for display.
playRatenumberCurrent playback rate multiplier (e.g. 1 = 1×, 2 = 2×).
play()() => voidStart playback from the current position. Plays to the end of the timeline and then stops.
pause()() => voidPause playback at the current position.
stop()() => voidStop playback and reset the cursor to time 0.
toStart()() => voidPause and jump the cursor back to time 0.
rewind()() => voidJump backwards by seekStep seconds (clamped to 0).
forward()() => voidJump forwards by seekStep seconds.
setTime(time)(time: number) => voidJump to a specific time value (seconds).
setPlayRate(rate)(rate: number) => voidChange the playback rate multiplier.

<TransportBar /> Component

A pre-built professional playback controls UI. It renders transport controls (to-start, rewind, play/pause, forward, stop), a time display, playback rate buttons, and optionally a loop toggle with start/end inputs.

Props

PropTypeDescription
playerTimelinePlayerState(Required) The return value of useTimelinePlayer(). Provides all reactive state and control functions.
loopTransportBarLoopPropsOptional loop controls. When provided, a loop toggle button appears, and start/end time inputs appear when the loop is active.
playRatesnumber[]Playback rate options displayed as speed buttons. Default is [0.25, 0.5, 1, 2, 4].
formatDisplayTime(seconds: number) => stringCustom time format function. Receives the current time in seconds, should return a display string. Default produces 'M:SS.mm' format.
classNamestringAdditional CSS class name for the transport bar root element.
styleReact.CSSPropertiesInline styles for the transport bar root element.

TransportBarLoopProps

PropertyTypeDescription
enabledbooleanWhether the loop is currently active. Controls the visual state of the loop button (lit vs. dim).
startnumberLoop region start time in seconds.
endnumberLoop region end time in seconds.
onToggle() => voidCalled when the user clicks the loop toggle button.
onStartChange(time: number) => voidCalled when the user edits the loop start input.
onEndChange(time: number) => voidCalled when the user edits the loop end input.

Basic Usage

import React, { useRef } from "react";
import {
  Timeline,
  TimelineState,
  TransportBar,
  useTimelinePlayer,
} from "@keplar-404/react-timeline-editor";

export const App = () => {
  const timelineRef = useRef<TimelineState>(null);
  const player = useTimelinePlayer(timelineRef);

  return (
    <div>
      <TransportBar player={player} />
      <Timeline ref={timelineRef} editorData={[]} effects={{}} />
    </div>
  );
};

formatTime Utility

Formats a time value in seconds to a M:SS.mm display string.

function formatTime(seconds: number): string;
formatTime(0); // '0:00.00'
formatTime(75.4); // '1:15.40'
formatTime(3661.1); // '61:01.10'

On this page