AudioComponent
ClassUsed to play audio in a Lens.
- Available on all platforms
Index
Properties
Methods
Remarks
You can assign an AudioTrackAsset to play through script, or through the Audio Component input in the Inspector panel of Lens Studio.
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");
});
Extends
Properties
audioTrack
audioTrack:
AudioTrackAsset
The audio asset currently assigned to play.
Default Value
null
duration
readonlyduration:number
The length (in seconds) of the current sound assigned to play.
enabled
enabled:
boolean
If disabled, the Component will stop enacting its behavior.
Default Value
true
Inherited from
fadeInTime
fadeInTime:
number
Length (in seconds) of a volume fade in applied to the beginning of sound playback.
fadeOutTime
fadeOutTime:
number
Length (in seconds) of a volume fade out applied to the end of sound playback.
isBeingDestroyed
readonlyisBeingDestroyed:boolean
Returns true if this Component is currently being destroyed. Becomes true as soon as
destruction begins via Component#destroy or destruction of its owning SceneObject,
before any OnDestroyEvent callbacks fire.
Since
Lens Scripting Version 364
Example
if (!script.isBeingDestroyed) {
// Component is still fully alive
}
Inherited from
isEnabledInHierarchy
readonlyisEnabledInHierarchy:boolean
Returns true if this Component, its SceneObject, and all of that SceneObjects parents are enabled.
Inherited from
Component.isEnabledInHierarchy
mixToSnap
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.
Since
Lens Scripting Version 147
Default Value
false
playbackMode
playbackMode:
PlaybackMode
SPECS
How the audio should be played back. Useful in optimizing audio in Spectacles.
Default Value
Audio.PlaybackMode.LowPower
@snapOS
position
position:
number
The current playback time in seconds
recordingVolume
recordingVolume:
number
The volume of audio recorded to the snap, from 0 to 1.
Since
Lens Scripting Version 147
Default Value
1
sceneObject
readonlysceneObject:SceneObject
The SceneObject this component is on.
Inherited from
spatialAudio
readonlyspatialAudio:SpatialAudio
Spatial Audio settings.
Since
Lens Scripting Version 147
uniqueIdentifier
readonlyuniqueIdentifier:string
Since
Lens Scripting Version 176
Inherited from
volume
volume:
number
A volume multiplier for any sounds played by this AudioComponent.
Default Value
1.0
Methods
destroy()
destroy():
void
Destroys the component.
Returns
void
Inherited from
getSceneObject()
getSceneObject():
SceneObject
Returns the SceneObject the component is attached to.
Returns
Inherited from
getTransform()
getTransform():
Transform
Returns the Transform this component is attached to.
Returns
Inherited from
getTypeName()
staticgetTypeName():TypeName<AudioComponent>
Returns the fully-qualified JavaScript type name for this class (for example, "Component.Camera"). This is a static accessor (no instance required) and returns the same value as the instance getTypeName().
Returns
TypeName<AudioComponent>
Overrides
getTypeName()
getTypeName():
string
Returns the name of this object's type.
Returns
string
Inherited from
isOfType()
isOfType(
type):boolean
Returns true if the object matches or derives from the passed in type.
Parameters
| Parameter | Type |
|---|---|
type | string |
Returns
boolean
Inherited from
isPaused()
isPaused():
boolean
Returns whether the sound is currently paused.
Returns
boolean
isPlaying()
isPlaying():
boolean
Returns whether the AudioComponent is currently playing sound.
Returns
boolean
isSame()
isSame(
other):boolean
Returns true if this object is the same as other. Useful for checking if two references point to the same thing.
Parameters
| Parameter | Type |
|---|---|
other | ScriptObject |
Returns
boolean
Inherited from
pause()
pause():
boolean
Pauses the sound.
Returns
boolean
play()
play(
loops):void
Plays the current sound loops number of times. If loops is -1, the sound will repeat forever.
Parameters
| Parameter | Type |
|---|---|
loops | number |
Returns
void
resume()
resume():
boolean
Resumes a paused sound.
Returns
boolean
setOnFinish()
setOnFinish(
eventCallback):void
Sets the callback function to be called whenever this sound stops playing.
Parameters
| Parameter | Type |
|---|---|
eventCallback | (audioComponent) => void |
Returns
void
stop()
stop(
fade):void
Stops the current sound if already playing.
Parameters
| Parameter | Type |
|---|---|
fade | boolean |
Returns
void
See also
Playing Audio guide for more information.