Hello,
I am getting started with Three.js and am trying to play sounds.
After trying a lot of scripts and also the official one, I am still getting this error when trying to play a mp3: “Unable to decode audio data”.
This is my script:
const camera = new THREE.PerspectiveCamera(75, window_width / window_height, 0.1, 100);
…
document.addEventListener(‘click’, function() {
this.listener = new THREE.AudioListener();
camera.add(this.listener);
const sound = new THREE.PositionalAudio(this.listener);
const loader = new THREE.AudioLoader();
loader.load(‘./sfx/SKRILLEX-KYOTO.mp3’, (buffer) => {
sound.setBuffer(buffer);
sound.setVolume(0.5);
sound.play();
From what I can see, your script is fully written in base Html and Javascript.
I am trying to utilize the audio system by Three.js, sorry if I was not clear
Yeah, I had to change it to “src/sfx/SKRILLEX-KYOTO.mp3” instead of having “sfx/SKRILLEX-KYOTO.mp3”. I thought I had already tried that, but it seems not