BufferGeometry
Object3D
Raycaster
Camera
CubeCamera
PerspectiveCamera
OrthographicCamera
StereoCamera
Clock
Curve
CurvePath
Path
Shape
ShapePath
ArrowHelper
AxesHelper
BoxHelper
Box3Helper
CameraHelper
DirectionalLightHelper
GridHelper
PolarGridHelper
HemisphereLightHelper
PlaneHelper
PointLightHelper
SkeletonHelper
SpotLightHelper
Light
PointLight
RectAreaLight
SpotLight
DirectionalLight
HemisphereLight
LightShadow
PointLightShadow
AnimationLoader
AudioLoader
BufferGeometryLoader
CompressedTextureLoader
CubeTextureLoader
DataTextureLoader
FileLoader
ImageBitmapLoader
ImageLoader
Loader
LoaderUtils
MaterialLoader
ObjectLoader
TextureLoader
LoadingManager
Material
Box2
Box3
Color
Cylindrical
Euler
Frustum
Interpolant
Line3
MathUtils
Matrix3
Matrix4
Plane
Quaternion
AnimationAction
AnimationClip
AnimationMixer
AnimationObjectGroup
AnimationUtils
keyframeTrack
PropertyBinding
PropertyMixer
BooleanKeyframeTrack
QuaternionKeyframeTrack
StringKeyframeTrack
Audio
AudioAnalyser
AudioContext
AudioListener
PositionalAudio

Audio.setVolume()

The setVolume() method is used to set the volume of an Audio object in the Three.js library. The Audio object represents an audio file that can be played in a Three.js scene.

Syntax

audio.setVolume( volume )
  • audio - The Audio object whose volume is to be set.
  • volume - A number between 0 and 1 that represents the new volume for the Audio object. A value of 0 will completely mute the audio, while a value of 1 will set the volume to maximum.

Example

var listener = new THREE.AudioListener();
var sound = new THREE.Audio( listener );
var audioLoader = new THREE.AudioLoader();
audioLoader.load( 'sounds/song.mp3', function( buffer ) {
    sound.setBuffer( buffer );
    sound.setLoop( true );
    sound.setVolume( 0.5 );
    sound.play();
});

In this example, an Audio object is created and loaded with a song file using the AudioLoader object. The setVolume() method is then used to set the volume of the sound object to 50% (0.5).

Notes

  • The volume of an Audio object can be changed at any time using the setVolume() method.
  • The setVolume() method does not affect the volume of the computer or device playing the audio. It only affects the volume of the Audio object within the Three.js scene.
  • The setVolume() method can be used to fade in or out an Audio object by gradually increasing or decreasing the volume over time.