Play audio once if PositionalAudio is in view

Hi all,

Just a quick and silly question.

Currently I’m using the PositionalAudio with a looping audio file when the camera is near. Works great! I was wondering; is it also possible (directly out and of the box) to (re)start playing the audio one time (then stop it) when the camera is over/near?

Or the only way is doing it myself by checking whenever the mesh (+audio attached) is in view (like: “frustum.containsPoint(speaker.position)”)?


You could also compute the euclidian distance in squared space and compare it with a predefined radius. This should be your preferred solution especially when the positional audio is omnidirectional.

Yes, thanks for your reply. I will implement something myself.

Btw: I have tried to adjust the Audio.setVolume(…) after the audio has been loaded and it looks like that does not work (while playing).

Only when I uses the setMasterVolume on the AudioListener is has effect. Did I miss something here?

I’ve changed one of the official audio examples to show that setVolume() seems to work (the method is called 2 seconds after the scene starts rendering).

Can you maybe change the fiddle in order to demonstrate the issue?

Ah ok. Well, I was tying to change the volume of my Audio (using setVolume) in my update loop to make a bit dynamic. Not the PositionalAudio one.

Thanks for your fiddle. When I change your PositionalAudio to just “Audio” and change the setVolume in the update loop. It’s not working as expected? Looks like there is some ‘lag’ or the browser doesn’t like so many updates of the volume.

See here: