2

How can I get the current volume output using Java? I've searched and found lots of examples that get only the volume setting. For example on windows 7, I can set the volume to 100% but when music plays, there'll be a green bar in volume mixer moving up and down according to the current volume of the sound.

That is the sound volume percentage I want to get, is this possible in Java?

Gary
  • 13,303
  • 18
  • 49
  • 71
Dan
  • 21
  • 2
  • Suppose it would be possible if you get the maximum value permitted and the lowest value permitted and current value. This will allow you to calculcate the percentage – John Snow May 07 '13 at 09:37
  • I don't think the Java API lets you 'peek' at the output waveform or amplitudes. It allows you to generate them, but then they're off into the internals of Windows. – Thomas W May 07 '13 at 09:42

2 Answers2

0

Suppose it would be possible if you get the maximum value permitted and the lowest value permitted and current value. This will allow you to calculcate the percentage.

FloatControl have the following methods: getmaximum(), getMinimum(), getCurrent() use them along with FloatControl type MASTER_GAIN

Use this along with the volume changing tutorials that is avaliable on the net

John Snow
  • 5,214
  • 4
  • 37
  • 44
  • that's the problem, how do the get the "current value" in order to calculate the percentage? – Dan May 07 '13 at 10:01
  • found [this post](http://stackoverflow.com/questions/14301618/can-java-sound-be-used-to-control-the-system-volume) that might be helpful – John Snow May 07 '13 at 10:11
0

Do you want to do gain meter like green meters here? What you have to do is sample sound from system and visualise sample value. Normally your sound card is 16bit, so you will get short int samples (−32,768 to 32,767). The simplest case is to have 16-bar meter, and then you will only light up one bar for one bit of sample.

tutejszy
  • 602
  • 7
  • 22