@threlte/extras
<Audio>
Create a non-positional (global) audio object. This uses the Web Audio API.
You need to have an <AudioListener>
component in your scene in order to use <Audio>
and <PositionalAudio>
components. The <AudioListener>
component needs to be mounted before any <Audio>
or <PositionalAudio>
components:
<T.PerspectiveCamera makeDefault>
<AudioListener />
</T.PerspectiveCamera>
<PositionalAudio />
Example
<script>
import { T, Canvas } from '@threlte/core'
import { AudioListener, Audio } from '@threlte/extras'
</script>
<Canvas>
<T.PerspectiveCamera
makeDefault
position={[3, 3, 3]}
lookAt={[0, 0, 0]}
>
<AudioListener />
</T.PerspectiveCamera>
<Audio src={'/audio/track.mp3'} />
</Canvas>