メインコンテンツへスキップ

audio

Description

This library includes functions that handle audio playback.

Audio

PropertyTypeDefaultDescription
url (Required)string''Source URL
volumenumber1How loud the audio will be played. A value between 0 and 1
loopbooleanfalseWheather the audio restarts after it finishes
pausedbooleanfalseWeather the audio is currently paused
pitchnumber1The factor used to change the audio's pitch. 1 is the default pitch.
positionalbooleanfalseweather the audio is played positional
refDistancenumber1Only applied if positional is true. The value indicating at what distance the volume from this source will start reducing as the listener moves away. Must be a non-negative value.
distanceModelstring'inverse'Only applied if positional is true. The algorithm used to reduce volume as the distance increases between this audio source and the listener. Possible values include 'linear', 'inverse', and 'exponential'.
rolloffFactornumber1Only applied if positional is true. How quickly volume is reduced as distance increases between this audio source and the listener. The acceptable range of values changes depending on the distanceModel, shown by the following: linear: 0 to 1, inverse: 0 to Infinity, exponential: 0 to Infinity
maxDistancenumber10000Only applied if positional is true and distanceModel equals linear. The max distance between this audio source and the listener. Volume is not reduced after this point. Must be a positive value.

Sound

PropertyTypeDescription
ideidThe eid of the sound.
audioNodeAudio / PositionalAudioAudioNode
elementHTMLAudioElementThe HTML audio element.
controllerAbortControllerThe audio AbortController.
urlstringThe source URL
pausedbooleanWhether the audio is paused or currently playing.

Properties

PropertyTypeDescription
listenerAudioListenerA virtual listener of the all positional and non-positional audio effects in the scene.

Functions

mute

Mute scene audio.

world.audio.mute() // -> void

unmute

Unmute scene audio.

world.audio.unmute() // -> void

pause

Pause scene audio.

world.audio.pause() // -> void

play

Play scene audio.

world.audio.play() // -> void

setVolume

Set volume of scene audio. The parameter should be a value between 0 and 1.

world.audio.setVolume(newVolume: number) // -> void