Lens Scripting API

    Class AudioComponent

    Used to play audio in a Lens.

    You can assign an AudioTrackAsset to play through script, or through the Audio Component input in the Inspector panel of Lens Studio.

    Playing Audio guide for more information.

    //@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");
    });

    Hierarchy (View Summary, Expand)

    Index

    Constructors

    Properties

    audioTrack: AudioTrackAsset

    The audio asset currently assigned to play.

    duration: number

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

    enabled: boolean

    If disabled, the Component will stop enacting its behavior.

    fadeInTime: number

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

    fadeOutTime: number

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

    mixToSnap: boolean

    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.

    playbackMode: Audio.PlaybackMode

    How the audio should be played back. Useful in optimizing audio in Spectacles.

    position: number

    The current playback time in seconds

    recordingVolume: number

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

    sceneObject: SceneObject

    The scene object this component is on.

    spatialAudio: SpatialAudio

    Spatial Audio settings.

    uniqueIdentifier: string
    volume: number

    A volume multiplier for any sounds played by this AudioComponent.

    Methods

    • Destroys the component.

      Returns void

    • Returns the name of this object's type.

      Returns string

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

      Parameters

      • type: string

      Returns boolean

    • Returns whether the sound is currently paused.

      Returns boolean

    • Returns whether the AudioComponent is currently playing sound.

      Returns boolean

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

      Parameters

      Returns boolean

    • Pauses the sound.

      Returns boolean

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

      Parameters

      • loops: number

      Returns void

    • Resumes a paused sound.

      Returns boolean

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

      Parameters

      Returns void

    • Stops the current sound if already playing.

      Parameters

      • fade: boolean

      Returns void

    MMNEPVFCICPMFPCPTTAAATR