我希望可以通过一个命令将电脑的主音量调高或者调低至100%或0%。
我看到可以使用FloatControl
来实现,但是我不确定该如何使用。
Mixer.Info [] mixers = AudioSystem.getMixerInfo();
System.out.println("There are " + mixers.length + " mixer info objects");
for (Mixer.Info mixerInfo : mixers)
{
System.out.println("Mixer name: " + mixerInfo.getName());
Mixer mixer = AudioSystem.getMixer(mixerInfo);
Line.Info [] lineInfos = mixer.getTargetLineInfo(); // target, not source
for (Line.Info lineInfo : lineInfos)
{
System.out.println(" Line.Info: " + lineInfo);
Line line = null;
boolean opened = true;
try
{
line = mixer.getLine(lineInfo);
opened = line.isOpen() || line instanceof Clip;
if (!opened)
{
line.open();
}
FloatControl volCtrl = (FloatControl)line.getControl(FloatControl.Type.VOLUME);
System.out.println(" volCtrl.getValue() = " + volCtrl.getValue());
}
catch (LineUnavailableException e)
{
e.printStackTrace();
}
catch (IllegalArgumentException iaEx)
{
System.out.println(" " + iaEx);
}
finally
{
if (line != null && !opened)
{
line.close();
}
}
}
}
FloatControl
。AudioInputStream audioInputStream =
AudioSystem.getAudioInputStream(new File("MyClip.wav"));
Clip clip = AudioSystem.getClip();
clip.open(audioInputStream);
FloatControl volumeControl =
(FloatControl) clip.getControl(FloatControl.Type.VOLUME);
volumeControl.setValue(10.0f); // Increase volume by 10 decibels.
clip.start();