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

The stop() method of the Audio object in Three.js is used to stop playback of the audio.

Syntax

audio.stop();

Parameters

This method takes no parameters.

Description

The Audio object is used to play audio files in a browser. When the stop() method is called, the current playback of the audio is immediately stopped and the audio is returned to the beginning of the file.

Example

// create an Audio object

var audio = new THREE.Audio( listener );

// set the audio file

var audioLoader = new THREE.AudioLoader();

audioLoader.load( 'song.mp3', function( buffer ) {

    audio.setBuffer( buffer );
    audio.setLoop( true );
    audio.setVolume( 0.5 );
    audio.play();

});

// stop the audio playback

audio.stop();

In this example, an Audio object is created and an MP3 file is loaded into it using the AudioLoader object. The audio is set to loop continuously and be played at half volume. The play() method is called to start the playback, and the stop() method is called to stop playback immediately.

Compatibility

The stop() method is only available in Three.js versions 0.81 and above.

See Also