音频用Java调高/调低电脑音量? 1 周,1 日 Questions & Answers 8597 我只需要一个命令就可以把电脑的主音量调高或调低(100%/0%)。 我看到我可以使用FloatControl,但我不知道如何使用它
# 1 楼答案 看看using JavaSound to control the master volume 从链接: 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(); } } } }
# 1 楼答案
看看using JavaSound to control the master volume
从链接: