n-sound

altspace/components. n-sound

Play a sound from a particular location. Limiting sound duration to 5 seconds or less is recommended to prevent hitching when the sound loads.

Example
<a-entity n-sound='res: effects/fanfare-start; on: begin'></a-entity>

Extends

Members

autoplay :boolean

Tells the clip to start automatically when the scene loads, instead of waiting for playSound().

Default Value:
  • false

loop :boolean

Tells the clip to loop back to the beginning of the clip once it's finished.

Default Value:
  • false

maxDistance :number

If rolloff is 'logarithmic', the sound will stop attenuating at this distance in meters. If rolloff is 'linear' or 'cosine', the sound will be silent at this distance.

Default Value:
  • 12

minDistance :number

Inside this distance in meters, the sound is at full volume.

Default Value:
  • 1

on :string

The name of the event that will play this sound clip.

oneshot :boolean

Tells the clip to clean itself up when it finishes playing. Allows for overlapping instances of the sound.

Default Value:
  • false

pitch :number

The speed multiplier for the sound. 0.5 is one octave down, and 2 is one octave up.

Default Value:
  • 1

res :string

Play the sound given by the src or res property from the location of the entity. The resource identifier for a built-in sound clip.

rolloff :string

Set this to 'linear' or 'cosine' if you want to cut sounds off at a maxDistance.

Default Value:
  • "logarithmic"

spatialBlend :number

How spatialized a sound is, from [0,1]. A value of 1 will be fully localized, and the sound will pan left and right as you turn your head. A value of 0 makes it non-spatialized, and it will always be heard in both ears.

Default Value:
  • 1

src :string

A URL to an external sound clip. The sound can be in WAV, OGG or MP3 format. However, only WAV is supported on all platforms. MP3 is supported on Gear VR and OGG is supported on desktop.

volume :number

The volume of the clip, from [0,1].

Default Value:
  • 1

Events

n-sound-loaded

Fired when a sound has loaded and is ready to be played

sound-paused

Emitted when the sound stops playing

sound-played

Emitted when the sound starts playing