Description

Used to play audio in a Lens. You can assign an AudioTrackAsset to play through script or through the AudioComponent's inspector in Lens Studio. See the Playing Audio guide for more information.

Example

//@input Component.AudioComponent audio
// Play once
script.audio.play(1);
// Play forever
script.audio.play(-1);
// If playing, stop
if(script.audio.isPlaying())
{
script.audio.stop(true);
}
// Set a callback for when the sound stops playing
script.audio.setOnFinish(function()
{
print("sound finished playing");
});
interface AudioComponent {
    audioTrack: AudioTrackAsset;
    duration: number;
    enabled: boolean;
    fadeInTime: number;
    fadeOutTime: number;
    mixToSnap: boolean;
    position: number;
    recordingVolume: number;
    spatialAudio: SpatialAudio;
    uniqueIdentifier: string;
    volume: number;
    destroy(): void;
    getSceneObject(): SceneObject;
    getTransform(): Transform;
    getTypeName(): string;
    isOfType(type): boolean;
    isPaused(): boolean;
    isPlaying(): boolean;
    isSame(other): boolean;
    pause(): boolean;
    play(loops): void;
    resume(): boolean;
    setOnFinish(eventCallback): void;
    stop(fade): void;
}

Hierarchy (view full)

Properties

audioTrack: AudioTrackAsset

Description

The audio asset currently assigned to play.

duration: number

Description

The length (in seconds) of the current sound assigned to play.

enabled: boolean

Description

If disabled, the Component will stop enacting its behavior.

fadeInTime: number

Description

Length (in seconds) of a volume fade in applied to the beginning of sound playback.

fadeOutTime: number

Description

Length (in seconds) of a volume fade out applied to the end of sound playback.

mixToSnap: boolean

Description

When true, records sound directly into the snap. This mode works only when all Audio Components in the scene are using mix to snap. In this case input from microphone will be ignored.

position: number

Description

The current playback time in seconds

recordingVolume: number

Description

The volume of audio recorded to the snap, from 0 to 1.

spatialAudio: SpatialAudio

Description

Spatial Audio settings.

uniqueIdentifier: string
volume: number

Description

A volume multiplier for any sounds played by this AudioComponent.

Methods

  • Returns void

    Description

    Destroys the component.

  • Returns string

    Description

    Returns the name of this object's type.

  • Parameters

    • type: string

    Returns boolean

    Description

    Returns true if the object matches or derives from the passed in type.

  • Returns boolean

    Description

    Returns whether the sound is currently paused.

  • Returns boolean

    Description

    Returns whether the AudioComponent is currently playing sound.

  • Parameters

    Returns boolean

    Description

    Returns true if this object is the same as other. Useful for checking if two references point to the same thing.

  • Returns boolean

    Description

    Pauses the sound.

  • Parameters

    • loops: number

    Returns void

    Description

    Plays the current sound loops number of times. If loops is -1, the sound will repeat forever.

  • Returns boolean

    Description

    Resumes a paused sound.

  • Parameters

    • eventCallback: ((audioComponent) => void)
        • (audioComponent): void
        • Parameters

          Returns void

    Returns void

    Description

    Sets the callback function to be called whenever this sound stops playing.

  • Parameters

    • fade: boolean

    Returns void

    Description

    Stops the current sound if already playing.

Generated using TypeDoc