Three.js: THREE.Audio getVolume() always gives 1 on Firefox

Created on 1 Sep 2019  路  12Comments  路  Source: mrdoob/three.js

myAudio= new THREE.Audio(listener);
myAudio.setVolume(0.5);
myAudio.getVolume(); //always gives 1

THREE.WebGLRenderer 104

Browser Issue

Most helpful comment

I can see what the problem is.

Chrome changed the behavior a while ago so the query to .value always returns the computed parameter value from the automation. The original (old) behavior is to return the value set by the setter. I think setTarget() doesn't really fit into that category so you get the value that is previously set by the setter.

Here's a link to the relevant discussion:
https://github.com/WebAudio/web-audio-api/issues/1788

Specifically this is Audio WG's decision on this issue:
https://github.com/WebAudio/web-audio-api/issues/1788#issuecomment-468345987

So Chrome's behavior is based on the spec and I expect other browsers will follow the spec change soon.

All 12 comments

The given volume of setVolume() is not directly assigned. Instead, AudioParam.setTargetAtTime() is used. So the volume is gradually changed over a certain amount of time.

You can easily verify this by retrieving the volume like so:

setTimeout( () => {

   console.log( audio.getVolume() );

}, 1000 );

Sorry if my example was wrong, but I always get audio.getVolume() = 1 even waiting, in firefox, this wroke some code that was functional on chrome.

Did this broke after updating Firefox? After updating Three? ...?

but I always get audio.getVolume() = 0 even waiting,

Can you still hear the audio?

Did this broke after updating Firefox? After updating Three? ...?

I usually use chrome so I only noticed after opening the project on firefox for the first time.

but I always get audio.getVolume() = 0 even waiting,

Can you still hear the audio?

Sorry I mean audio.getVolume() = 1, edited.
Yes, the sound works, you can even change the volume and it does change, but is getVolume the thing that is broken.

I've prepared a live example: https://jsfiddle.net/kavs8bL4/1/ (Click on the start button since a user interaction is required to start the audio context)

Indeed, it does work in Chrome but FF (68.0.2) and Safari (12.1.2) report a volume of 1.

@hoch are we doing something wrong?

@mrdoob @Mugen87 Can you pinpoint where audio.getVoume() happens?

I can see what the problem is.

Chrome changed the behavior a while ago so the query to .value always returns the computed parameter value from the automation. The original (old) behavior is to return the value set by the setter. I think setTarget() doesn't really fit into that category so you get the value that is previously set by the setter.

Here's a link to the relevant discussion:
https://github.com/WebAudio/web-audio-api/issues/1788

Specifically this is Audio WG's decision on this issue:
https://github.com/WebAudio/web-audio-api/issues/1788#issuecomment-468345987

So Chrome's behavior is based on the spec and I expect other browsers will follow the spec change soon.

Good to hear that! Thanks for the explanation 馃憤

Was this page helpful?
0 / 5 - 0 ratings