The stop()
method of the Audio
object in Three.js is used to stop playback of the audio.
audio.stop();
This method takes no parameters.
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.
// 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.
The stop()
method is only available in Three.js versions 0.81 and above.