How to adjust speaker volume from a Java program?

I start Win Vista, in the lower right part of the window there is a speaker icon next to the clock, I can click on it and adjust the volume, I wonder if there is a way in my Java program to do this automatically. For example, when my Java program starts, it turns the volume into 80, and when the program exits, it changes the volume back to its original level, I am not against using Runtime.getRuntime (). Exec () if there is a way to achieve this effect.

+3
source share
3 answers

I used the following code to simulate volume control:

Robot robot;             // Set speaker volume to 80
try
{
  robot=new Robot();
  robot.mouseMove(1828,1178);
  robot.mousePress(InputEvent.BUTTON1_MASK);
  robot.mouseRelease(InputEvent.BUTTON1_MASK);
  robot.delay(90);
  robot.mouseMove(1828,906);
  robot.mousePress(InputEvent.BUTTON1_MASK);
  robot.mouseRelease(InputEvent.BUTTON1_MASK);
  robot.delay(260);
  robot.mousePress(InputEvent.BUTTON1_MASK);
  robot.mouseRelease(InputEvent.BUTTON1_MASK);
}
catch (AWTException ex)
{
  System.err.println("Can't start Robot: " + ex);
  System.exit(0);
}

And it worked!

+2
source

Java , . SDK Java 1.4, . Java "cls", , .

, Java. JNI DLL ++, ++ # .

++:

win32 ++

+1

javax.sound API. , ( ) , . Google, .

+1

Source: https://habr.com/ru/post/1722865/


All Articles