Represents an audio src in the Wonderland Engine, allowing playback of audio files.

Hierarchy

  • Component
    • AudioSource

Properties

autoplay: boolean

Whether to autoplay the sound.

coneInnerAngle: number

The inner angle of the audio cone.

coneOuterAngle: number

The outer angle of the audio cone.

coneOuterGain: number

The outer gain of the audio cone.

distanceModel: DistanceModelType

The distance model used for spatial audio.

emitter: Emitter<[PlayState]> = ...

The emitter will notify all subscribers when a state change occurs.

PlayState

isStationary: boolean

Set this property if the object will never move. Disabling position updates each frame saves CPU time.

loop: boolean

Whether to loop the sound.

maxDistance: number

The maximum distance for audio falloff.

refDistance: number

The reference distance for audio falloff.

rolloffFactor: number

The rolloff factor for audio falloff.

spatial: PanningType

Select the panning method.

Enabling HRTF (Head-Related Transfer Function) is computationally more intensive than regular panning!

src: string

Path to the audio file that should be played.

volume: number

Volume of the audio source.

This will only take effect audio that has not started playing yet. Is the audio already playing, use setVolumeDuringPlayback()

setVolumeDuringPlayback

TypeName: string = 'audio-source'

The type name for this component.

Accessors

  • get isPlaying(): boolean
  • Checks if the audio src is currently playing.

    Returns boolean

  • get maxVolume(): number
  • Returns number

    Use #volume instead

  • set maxVolume(v): void
  • Parameters

    • v: number

    Returns void

    Use #volume instead

Methods

  • Change out the source.

    Parameters

    • path: string

      Path to the audio file.

    Returns Promise<void>

  • Called when the component is deactivated. Stops the audio playback.

    Returns void

  • Called when the component is destroyed. Stops the audio playback and removes the src from cache.

    Returns void

  • Plays the audio associated with this audio src.

    Parameters

    • buffer: AudioBuffer = ...

      Optional parameter that will set the raw audio buffer that should be played. Defaults to internal audio buffer that is set with given audio path.

    Returns Promise<void>

    Is this audio-source currently playing, playback will be restarted.

  • Parameters

    Returns void

  • Changes the volume during playback.

    Parameters

    • v: number

      Volume that source should have.

    • t: number = 0

      Optional parameter that specifies the time it takes for the volume to reach its specified value in seconds (Default is 0).

    Returns void

  • Initializes the audio src component. If autoplay is enabled, the audio will start playing as soon as the file is loaded.

    Returns Promise<void>

  • Stops the audio associated with this audio src.

    Returns void

  • Called when this component class is registered.

    Parameters

    • engine: WonderlandEngine

    Returns void

    This callback can be used to register dependencies of a component, e.g., component classes that need to be registered in order to add them at runtime with Object3D.addComponent, independent of whether they are used in the editor.

    class Spawner extends Component {
    static TypeName = 'spawner';

    static onRegister(engine) {
    engine.registerComponent(SpawnedComponent);
    }

    // You can now use addComponent with SpawnedComponent
    }

    This callback can be used to register different implementations of a component depending on client features or API versions.

    // Properties need to be the same for all implementations!
    const SharedProperties = {};

    class Anchor extends Component {
    static TypeName = 'spawner';
    static Properties = SharedProperties;

    static onRegister(engine) {
    if(navigator.xr === undefined) {
    /* WebXR unsupported, keep this dummy component */
    return;
    }
    /* WebXR supported! Override already registered dummy implementation
    * with one depending on hit-test API support */
    engine.registerComponent(window.HitTestSource === undefined ?
    AnchorWithoutHitTest : AnchorWithHitTest);
    }

    // This one implements no functions
    }