Discrepancy with audio listener between Chrome and Firefox

I am trying to do some positional audio using the Web Audio API. I have been working in Chrome and my code functions perfectly. However, when testing in firefox, I am getting errors because the listener doesn’t seem to have any of the correct properties (positionX etc.)

Focussing on these two lines of code:

var context = this.app.systems.sound.context;
var listener = context.listener;

When inspecting the listener in Chrome, it looks like this:

JS_Problem_02

But in Firefox, it looks like this:

So when later on I am using code like this:

var listener = this.context.listener;
var pos = this.camera.getPosition();
listener.positionX.value = pos.x;
listener.positionY.value = pos.y;
listener.positionZ.value = pos.z;

It runs fine in Chrome, but errors in Firefox.

Does anyone know why this would be happening?

Hi @steve_wk,

As you can see in the chart below,

firefox doesn’t support to directly set the position values and you have to use the functions setPosition and the setOrientation functions even though they are deprecated, alternatively, what I do is check
if it is supported or not by the browser doing this and use the compatible functions and hopefully when firefox adds the the newer functionality I wont have to update my code.

Capture

4 Likes

Thanks so much Saad, that’s really helpful!

1 Like