threlte logo
@threlte/extras

useThrelteAudio

When invoking the hook useThrelteAudio and there’s no Threlte audio context yet, it will be created and returned, otherwise, the existing audio context will be returned. The components <AudioListener>, <Audio> and <PositionalAudio> will create an audio context if mounted.

const {
  audioListeners, // Map<string, AudioListener>
  getAudioListener, // (id?: string) => AudioListener | undefined
  addAudioListener, // (listener: AudioListener, id?: string) => void
  removeAudioListener // (id?: string) => void
} = useThrelteAudio()