Page 2 of 2

Re: Separate Volume Controls

Posted: Mon Oct 31, 2016 7:49 pm
by another_commander
So, in the next nightly we should be able to control music volume, loop status, position etc in real time. Due to the way sound and music are set up internally, it is not entirely straightforward in the current implementation and it is possible that a better way to handle this exists, I just couldn't see it. Having said that, it's not difficult either, thankfully.

In order to enable this kind of control, I have exposed to Javascript the sound source object of the music currently playing. So, once we have access to that object, we can work with it like we do with any other sound source. The new function that does it is part of the Sound JS class and is called musicSoundSource. More specifically, if I want to adjust on the fly, say, the volume of the music currently playing, what I would do is something like this:

Code: Select all

myMusicSoundSource = Sound.musicSoundSource();
myMusicSoundSource.volume = 0.4;
If the music file is a 44KHz mono ogg, we can also do stuff like

Code: Select all

myMusicSoundSource.position = [-1,0,0]; // throw the currently playing music to the left channel

Re: Separate Volume Controls

Posted: Tue Nov 01, 2016 11:19 am
by Svengali
Muchas gracias, a_c! 8)