AudioInjector

Available in: Interface Scripts Client Entity Scripts Server Entity Scripts Assignment Client Scripts

Plays — "injects" — the content of an audio file. Used in the Audio API.
Methods

Signals

Type Definitions

Properties:
Name Type Description
playing boolean true if the audio is currently playing, otherwise false. Read-only.
loudness number The loudness in the last frame of audio, range 0.01.0. Read-only.
options AudioInjector.AudioInjectorOptions Configures how the injector plays the audio.

Methods

getLoudness() → {number}
Get the loudness of the most recent frame of audio played.
Returns:
The loudness of the most recent frame of audio played, range 0.01.0.
Type: number
getOptions() → {AudioInjector.AudioInjectorOptions}
Get the current configuration of the audio injector.
Returns:
Configuration of how the injector plays the audio.
Type: AudioInjector.AudioInjectorOptions
isPlaying() → {boolean}
Get whether or not the audio is currently playing.
Returns:
true if the audio is currently playing, otherwise false.
Type: boolean
Example

See if a sound is playing.

var sound = SoundCache.getSound(Script.resourcesPath() + "sounds/sample.wav");
var injector;
var injectorOptions = {
  position: MyAvatar.position
};

Script.setTimeout(function () { // Give the sound time to load.
  injector = Audio.playSound(sound, injectorOptions);
}, 1000);

Script.setTimeout(function () {
  print("Sound is playing: " + injector.isPlaying());
}, 2000);
restart()
Stop current playback, if any, and start playing from the beginning.
setOptions(options)
Configure how the injector plays the audio.
Parameters:
Name Type Description
options AudioInjector.AudioInjectorOptions Configuration of how the injector plays the audio.
stop()
Stop audio playback.
Example

Stop playing a sound before it finishes.

var sound = SoundCache.getSound(Script.resourcesPath() + "sounds/sample.wav");
var injector;
var injectorOptions = {
  position: MyAvatar.position
};

Script.setTimeout(function () { // Give the sound time to load.
  injector = Audio.playSound(sound, injectorOptions);
}, 1000);

Script.setTimeout(function () {
  injector.stop();
}, 2000);
stopInjectorImmediately()
Stop audio playback. (Synonym of stop.)

Signals

finished() → {Signal}
Triggered when the audio has finished playing.
Returns:
Type: Signal
Example

Report when a sound has finished playing.

var sound = SoundCache.getSound(Script.resourcesPath() + "sounds/sample.wav");
var injector;
var injectorOptions = {
  position: MyAvatar.position
};

Script.setTimeout(function () { // Give the sound time to load.
  injector = Audio.playSound(sound, injectorOptions);
  injector.finished.connect(function () {
      print("Finished playing sound");
  });
}, 1000);

Type Definitions

AudioInjectorOptions
Configures how an audio injector plays its audio.
Type: object
Properties:
Name Type Default Description
position Vec3 Vec3.ZERO The position in the domain to play the sound.
orientation Quat Quat.IDENTITY The orientation in the domain to play the sound in.
volume number 1.0 Playback volume, between 0.0 and 1.0.
pitch number 1.0 Alter the pitch of the sound, within +/- 2 octaves. The value is the relative sample rate to resample the sound at, range 0.062516.0. A value of 0.0625 lowers the pitch by 2 octaves; 1.0 is no change in pitch; 16.0 raises the pitch by 2 octaves.
loop boolean false If true, the sound is played repeatedly until playback is stopped.
secondOffset number 0 Starts playback from a specified time (seconds) within the sound file, ≥ 0.
localOnly boolean false IF true, the sound is played back locally on the client rather than to others via the audio mixer.
ignorePenumbra boolean false Deprecated: This property is deprecated and will be removed.