I implemented a audio like this and I am toggling with a button. When I initially click a button it is playing sound after I click another time sound is still coming volume also not decreasing

function playSound() {
const listner = new THREE.AudioListener();
const audioLoader = new THREE.AudioLoader();
const background = new THREE.Audio(listner);

audioLoader.load(suzume, function(buffer) {
  click ? background.setLoop(true) : background.setLoop(0)
  background.setVolume(click ? 0.1 : 0) 
  click ? background.play() : background.pause()
  audioRef.current = background;


Not a direct answer to the question, but if you’re serious about using audio in your app - consider using Howler instead. Three’s Audio API is quite simple, good for demos, a bit hard to work with in bigger projects.

1 Like