Skip to main content
Controllers provide the interface between the <helios-player> element and the Helios composition. They handle communication, state synchronization, and frame capture.

Controller types

There are two controller implementations:
  • DirectController - Used when the composition is same-origin and accessible via direct JavaScript reference
  • BridgeController - Used when the composition is cross-origin and requires message-based communication
The player automatically selects the appropriate controller based on iframe access permissions.

HeliosController interface

Both controllers implement the HeliosController interface:

Playback control

play()

Starts or resumes playback.

pause()

Pauses playback.

seek(frame)

Seeks to a specific frame.
Parameters:
  • frame (number) - Target frame number
Returns: Promise<void> - Resolves when seek completes

Audio control

setAudioVolume(volume)

Sets the master audio volume.
Parameters:
  • volume (number) - Volume level from 0.0 to 1.0

setAudioMuted(muted)

Mutes or unmutes all audio.
Parameters:
  • muted (boolean) - Whether audio should be muted

setAudioTrackVolume(trackId, volume)

Sets the volume for a specific audio track.
Parameters:
  • trackId (string) - Audio track identifier
  • volume (number) - Volume level from 0.0 to 1.0

setAudioTrackMuted(trackId, muted)

Mutes or unmutes a specific audio track.
Parameters:
  • trackId (string) - Audio track identifier
  • muted (boolean) - Whether track should be muted

Playback configuration

setLoop(loop)

Enables or disables looping playback.
Parameters:
  • loop (boolean) - Whether playback should loop

setPlaybackRate(rate)

Sets the playback speed.
Parameters:
  • rate (number) - Speed multiplier (1.0 = normal)

setPlaybackRange(startFrame, endFrame)

Sets a custom playback range.
Parameters:
  • startFrame (number) - First frame of range
  • endFrame (number) - Last frame of range (exclusive)

clearPlaybackRange()

Clears the playback range, restoring full duration playback.

Captions

setCaptions(captions)

Sets captions from VTT string or cue array.
Parameters:
  • captions (string | CaptionCue[]) - VTT string or caption cue array

Composition properties

setInputProps(props)

Sets input properties for the composition schema.
Parameters:
  • props (Record) - Property key-value pairs

setDuration(seconds)

Overrides the composition duration.
Parameters:
  • seconds (number) - Duration in seconds

setFps(fps)

Overrides the composition frame rate.
Parameters:
  • fps (number) - Frames per second

setSize(width, height)

Sets the composition dimensions.
Parameters:
  • width (number) - Width in pixels
  • height (number) - Height in pixels

setMarkers(markers)

Sets timeline markers.
Parameters:
  • markers (Marker[]) - Array of marker objects

State and events

subscribe(callback)

Subscribes to state changes.
Parameters:
  • callback ((state: any) => void) - Called on each state update
Returns: () => void - Unsubscribe function State object properties:
  • currentFrame (number) - Current frame
  • isPlaying (boolean) - Playing state
  • duration (number) - Duration in seconds
  • fps (number) - Frame rate
  • volume (number) - Master volume
  • muted (boolean) - Muted state
  • playbackRate (number) - Playback speed
  • width (number) - Composition width
  • height (number) - Composition height
  • availableAudioTracks (array) - Available audio tracks
  • audioTracks (array) - Active audio tracks
  • activeCaptions (CaptionCue[]) - Currently visible captions
  • playbackRange ([number, number] | null) - Active playback range

onError(callback)

Subscribes to error events.
Parameters:
  • callback ((error: any) => void) - Called when errors occur
Returns: () => void - Unsubscribe function

getState()

Returns the current state synchronously.
Returns: State object (see subscribe() for properties)

Frame capture

captureFrame(frame, options)

Captures a single frame as a VideoFrame.
Parameters:
  • frame (number) - Frame number to capture
  • options (object, optional)
    • selector (string) - CSS selector for canvas (default: 'canvas')
    • mode (‘canvas’ | ‘dom’) - Capture mode
    • width (number) - Output width (scales if different)
    • height (number) - Output height (scales if different)
Returns: Promise<{ frame: VideoFrame, captions: CaptionCue[] } | null>

Audio tracks

getAudioTracks()

Retrieves all audio assets from the composition.
Returns: Promise<AudioAsset[]> AudioAsset properties:
  • id (string) - Track identifier
  • buffer (AudioBuffer) - Decoded audio data
  • element (HTMLAudioElement) - Source audio element

Schema and diagnostics

getSchema()

Retrieves the composition schema definition.
Returns: Promise<HeliosSchema | undefined>

diagnose()

Generates a diagnostic report for debugging.
Returns: Promise<DiagnosticReport>

Audio metering

startAudioMetering()

Begins real-time audio level monitoring.

stopAudioMetering()

Stops audio level monitoring.

onAudioMetering(callback)

Subscribes to audio level updates.
Parameters:
  • callback ((levels: AudioLevels) => void) - Called with audio levels
Returns: () => void - Unsubscribe function AudioLevels properties:
  • peak (number) - Peak level (0.0 to 1.0)
  • rms (number) - RMS level (0.0 to 1.0)

Cleanup

dispose()

Cleans up resources and removes listeners.

DirectController

Used for same-origin compositions with direct access.

Constructor

Parameters:
  • instance (Helios) - Helios instance from the composition
  • iframe (HTMLIFrameElement, optional) - Iframe element containing the composition

Features

  • Direct method calls on Helios instance (no message passing overhead)
  • Synchronous state access
  • Built-in audio fading for smooth playback transitions
  • Real-time audio metering support

BridgeController

Used for cross-origin compositions using postMessage.

Constructor

Parameters:
  • iframeWindow (Window) - Window object of the composition iframe
  • initialState (object, optional) - Initial state object

Features

  • Message-based communication for cross-origin safety
  • Automatic message filtering by source
  • Promise-based async operations with timeouts
  • State caching to minimize message overhead

Bridge setup

The composition must call connectToParent() to enable bridge communication:

Example: Using controllers directly

Example: Bridge controller with error handling