我想通过一个命令来上下调节计算机的主音量(100%/0%)。我看到我可以使用FloatControl
,但我不知道如何使用它。
问问题
8688 次
2 回答
4
从链接:
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();
}
}
}
}
于 2013-01-12T23:10:47.117 回答
2
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();
另请参阅:使用控件处理音频
于 2013-01-12T23:11:40.947 回答