Skip to main content

Class: PlaybackController

Defined in: runtime/playback-controller.ts:44

Orchestrates playback of a compiled motion-script project.

On construction it runs the precomp pass (Precomp.run()) to build the global asset timeline and node lifespans, then wires the master clock to the audio device and render pipeline so every tick:

  1. Loads assets required at the current frame (AssetManager.loadAt).
  2. Evaluates scene state and lays out nodes (StateEvaluator).
  3. Renders the frame to the render context.
  4. Prefetches assets for upcoming frames.

External callers interact via play, pause, seek, seekWhilePlaying, screenshot, getTreeState, and getNodeState.

Constructors

Constructor

new PlaybackController(params): PlaybackController

Defined in: runtime/playback-controller.ts:78

Parameters

params

ControllerParams

Returns

PlaybackController

Properties

fps

readonly fps: number

Defined in: runtime/playback-controller.ts:54


precomp

readonly precomp: PrecompResult

Defined in: runtime/playback-controller.ts:56


viewport

readonly viewport: Size2D

Defined in: runtime/playback-controller.ts:55

Accessors

buildErrors

Get Signature

get buildErrors(): BuildError[]

Defined in: runtime/playback-controller.ts:74

Errors collected during the precomp pass (one entry per failing scene).

Returns

BuildError[]


currentFrame

Get Signature

get currentFrame(): number

Defined in: runtime/playback-controller.ts:142

Current playback position in frames (float).

Returns

number


currentTime

Get Signature

get currentTime(): number

Defined in: runtime/playback-controller.ts:137

Current playback position in seconds.

Returns

number


isPlaying

Get Signature

get isPlaying(): boolean

Defined in: runtime/playback-controller.ts:132

Returns

boolean


totalDuration

Get Signature

get totalDuration(): number

Defined in: runtime/playback-controller.ts:69

Total playback duration in seconds.

Returns

number


totalFrames

Get Signature

get totalFrames(): number

Defined in: runtime/playback-controller.ts:64

Total frame count across all scenes.

Returns

number


tracks

Get Signature

get tracks(): number[]

Defined in: runtime/playback-controller.ts:59

Per-scene frame counts in timeline order, used to build the track list.

Returns

number[]

Methods

dispose()

dispose(): void

Defined in: runtime/playback-controller.ts:263

Returns

void


getNodeState()

getNodeState(nodeId): NodeState | null

Defined in: runtime/playback-controller.ts:239

Parameters

nodeId

string

Returns

NodeState | null


getTreeState()

getTreeState(): TreeState | null

Defined in: runtime/playback-controller.ts:218

Return the full node tree for the current scene, with lifespan frame ranges and waveform data attached. Used by the timeline UI. Returns null when no scene is active.

Returns

TreeState | null


onPause()

onPause(cb): void

Defined in: runtime/playback-controller.ts:157

Register a callback that fires when playback pauses.

Parameters

cb

() => void

Returns

void


onPlay()

onPlay(cb): void

Defined in: runtime/playback-controller.ts:152

Register a callback that fires when playback starts.

Parameters

cb

() => void

Returns

void


onTime()

onTime(cb): void

Defined in: runtime/playback-controller.ts:147

Register a callback that fires on every clock tick with the current time.

Parameters

cb

TimeCallback

Returns

void


pause()

pause(): void

Defined in: runtime/playback-controller.ts:255

Returns

void


play()

play(speed?, reverse?): void

Defined in: runtime/playback-controller.ts:247

Parameters

speed?

number = 1

reverse?

boolean = false

Returns

void


screenshot()

screenshot(): string | undefined

Defined in: runtime/playback-controller.ts:208

Capture the current frame as a base-64 PNG data URL. Forces a fresh render before snapshotting because the WebGL drawing buffer may have been cleared since the last tick (we don't set preserveDrawingBuffer). Uses stateEvaluator.currentFrame (integer) rather than the clock's float so stateAt always hits its early-return and never resets scene state.

Returns

string | undefined


seek()

seek(frame): Promise<void>

Defined in: runtime/playback-controller.ts:183

Jump to frame, pausing playback first. Waits for required assets to load before rendering, then prefetches upcoming frames.

Parameters

frame

number

Returns

Promise<void>


seekWhilePlaying()

seekWhilePlaying(frame): void

Defined in: runtime/playback-controller.ts:196

Reposition the clock to frame without interrupting playback.

Parameters

frame

number

Returns

void


setMuted()

setMuted(muted): void

Defined in: runtime/playback-controller.ts:259

Parameters

muted

boolean

Returns

void