, , , , - .
( ).
(, -). nircmd.exe - . , :
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec(pathToNircmdexe + " setsysvolume 32767.5");
This will set your system volume to 50. To set the volume, you need to select a number from 0 to 65535. If you want to use numbers from 0 to 100, use the method below. It converts the desired volume (using simple mathematical data: D)
public void setSystemVolume(int volume)
{
if(volume < 0 || volume > 100)
{
throw new RuntimeException("Error: " + volume + " is not a valid number. Choose a number between 0 and 100");
}
else
{
double endVolume = 655.35 * volume;
Runtime rt = Runtime.getRuntime();
Process pr;
try
{
pr = rt.exec(nircmdFilePath + " setsysvolume " + endVolume);
pr = rt.exec(nircmdFilePath + " mutesysvolume 0");
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
Note: Unfortunately, this only works for windows,
"because Java is cross-platform, it cannot do things such as changing the volume or what you want to do to control the OS. To do this, you need to use a unique API level for the operating system." source
source
share