AudioComponent
Lens Studio v1.0.0+
Scripting Name: Component.AudioComponent
Inherits from Component
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.
Methods
isPaused()
: Boolean
Returns whether the sound is currently paused.
isPlaying()
: Boolean
Returns whether the AudioComponent is currently playing sound.
pause()
: Boolean
Pauses the sound.
play(Number loops)
: void
Plays the current sound loops
number of times. If loops
is -1, the sound will repeat forever.
resume()
: Boolean
Resumes a paused sound.
setOnFinish(function(AudioComponent audioComponent) eventCallback)
: void
Sets the callback function to be called whenever this sound stops playing.
stop(Boolean fade)
: void
Stops the current sound if already playing.
Properties
audioTrack
: AudioTrackAsset
The audio asset currently assigned to play.
duration
: Number
The length (in seconds) of the current sound assigned to play.
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.
position
: Number
The current playback time in seconds
volume
: Number
A volume multiplier for any sounds played by this AudioComponent.
Inherited Methods
destroy()
: void
Destroys the component.
getSceneObject()
: SceneObject
Returns the SceneObject the component is attached to.
getTransform()
: Transform
Returns the Transform this component is attached to.
isSame(SerializableWithUID other)
: Boolean
Returns true if this object is the same as other
. Useful for checking if two references point to the same thing.
getTypeName()
: String
Returns the name of this object’s type.
isOfType(String type)
: Boolean
Returns true if the object matches or derives from the passed in type.
Inherited Properties
enabled
: Boolean
If disabled, the Component will stop enacting its behavior.
Examples
//@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");
});
Still Looking for help?
Visit Support