Skip to content

@relu-interactives/spatial-ecs


@relu-interactives/spatial-ecs / components / AudioComponent

Class: AudioComponent ​

Defined in: components/Audio.ts:27

Plays an audio clip from path. Supports both global stereo (positional: false) and 3D positional audio with the configured distance model. Runtime fields (object, audio, isPlaying, isPaused) are recreated when the project loads and are never persisted to saved snapshots.

Extends ​

Constructors ​

Constructor ​

ts
new AudioComponent(path, options?): AudioComponent;

Defined in: components/Audio.ts:64

Parameters ​

ParameterType
pathstring
optionsPartial<typeof DEFAULT_AUDIO_OPTIONS>

Returns ​

AudioComponent

Overrides ​

Component.constructor

Properties ​

PropertyTypeDescriptionDefined in
pathstringSource URL or localasset:// path of the audio file.components/Audio.ts:29
options{ autoplay: boolean; loop: boolean; pitch: number; volume: number; positional: boolean; refDistance: number; distanceModel: string; rolloffFactor: number; }Playback options.Field
options.autoplayboolean-components/Audio.ts:9
options.loopboolean-components/Audio.ts:10
options.pitchnumber-components/Audio.ts:11
options.volumenumber-components/Audio.ts:12
options.positionalboolean-components/Audio.ts:13
options.refDistancenumber-components/Audio.ts:14
options.distanceModelstring-components/Audio.ts:15
options.rolloffFactornumber-components/Audio.ts:16
objectObject3D<Object3DEventMap> | nullLive three.js object hosting the audio (a parented Audio/PositionalAudio). null until built.components/Audio.ts:46
audioAudio<GainNode> | PositionalAudio | nullLive three.js audio source. null until built. Recreated when the project loads.components/Audio.ts:48
isPlayingbooleanWhether the audio should be playing. Managed by AudioSystem in preview. Non-enumerable — not persisted to snapshots or save data. Set via play / stop.components/Audio.ts:55
isPausedbooleanWhether the audio is paused mid-playback (position is preserved). Non-enumerable — not persisted to snapshots or save data. Set via pause / play / stop.components/Audio.ts:62

Methods ​

play() ​

ts
play(): void;

Defined in: components/Audio.ts:98

Signals AudioSystem to start (or resume) playback. Has no direct effect in the editor — AudioSystem drives the actual THREE.js call in preview.

Returns ​

void


pause() ​

ts
pause(): void;

Defined in: components/Audio.ts:108

Signals AudioSystem to pause playback, preserving the current position. Calling play afterwards resumes from where it paused. No-op if not currently playing.

Returns ​

void


stop() ​

ts
stop(): void;

Defined in: components/Audio.ts:117

Signals AudioSystem to stop playback and reset the playback position.

Returns ​

void