The Audio.getPlaybackRate()
method is used to retrieve the current playback rate of an audio object in Three.js.
audioObject.getPlaybackRate();
None.
The return value is a Number representing the current playback rate of the audio object. A playback rate of 1.0
represents normal speed, while a rate of 2.0
represents double speed and 0.5
represents half speed.
const audioLoader = new THREE.AudioLoader();
const listener = new THREE.AudioListener();
const sound = new THREE.Audio(listener);
audioLoader.load('path/to/audio.mp3', function(buffer) {
sound.setBuffer(buffer);
sound.setLoop(true);
sound.setVolume(0.5);
sound.play();
});
// get the current playback rate of the sound
const rate = sound.getPlaybackRate();
The Audio.getPlaybackRate()
method is only available after an audio object has been created and its buffer has been set. It is often used in conjunction with the Audio.setPlaybackRate()
method to dynamically adjust the speed of playback in response to user input or other events.