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.setBuffer()

The setBuffer() method of Audio class in three.js library is used to set the AudioBuffer for the Audio object.

Syntax

audio.setBuffer(buffer);

Parameters

  • buffer - An instance of AudioBuffer representing the audio data to be set.

Example

// Create Audio object
var audio = new THREE.Audio( listener );

// Load Audio file
var loader = new THREE.AudioLoader();
loader.load( 'sounds/song.ogg', function( buffer ) {

    // Set the AudioBuffer to the Audio object
    audio.setBuffer( buffer );

} );

In the above example, Audio object is created and an audio file is loaded using AudioLoader. Once the audio file is loaded, the callback function is executed and the setBuffer() method is called to set the AudioBuffer for the Audio object.

Remarks

If the AudioBuffer is not set, the Audio object will not be able to play any sound. The setBuffer() method must be called after the audio file is loaded using AudioLoader and before the Audio object is played.

See Also