Unable to play mp3s

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();

//this.scene.add(this.audio);

});
});

This is a picture of my directory:

You try to play skrillex instead sound
image

How do you mean?

Also try another mp3 file

I have already done that with the “your_slaying_to_hard.mp3”

I try your code and sound work ok: https://codepen.io/illuminsi/pen/zxxXLXL

2 Likes

Yeah, weirdly it does as well when I paste the link of the audio into my script.
Do you know why my mp3s do not work?

I dont know english good. When you paste this link, work ok?
https://threejs.org/examples/sounds/webgpu-audio-processing.mp3

1 Like

Yes,
But only for this link, I can’t use local mp3s

This sounds like a CORS issue. Have you checked your local JavaScript console for any error messages?

3 Likes

Yeah, but it is not really a useful error/
This is the error I get:


This is the script I currently have:

Hi @Harnekampf
I made some changes in the code of old posts and prepare this page

Let us see if this helps…

1 Like

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

Did you put your audio in your src/assets/ directory?

I think its not finding the audio file, and trying to parse the 404 page as an audio file.

Can you check the “network” tab in the debugger for any files showing up in red?

Hi @Harnekampf
Here goes one page with THREE.AudioListener()…

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

1 Like