不,它不能。这是从“ 调整码位上的主音量”的答案改编而来的资源。源代码会迭代可用的行,检查它们是否具有正确类型的控件,如果有,则将它们放入连接到命令行的GUI中。
JSlider
import java.awt.*;import javax.swing.*;import javax.sound.sampled.*;import javax.swing.event.ChangeEvent;import javax.swing.event.ChangeListener;public class SoundMixer { public Component getGui() { JPanel gui = new JPanel(new GridLayout(0,1)); 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.getSourceLineInfo(); for (Line.Info lineInfo : lineInfos) { System.out.println(" Line.Info: " + lineInfo); try { Line line = mixer.getLine(lineInfo); FloatControl volCtrl = (FloatControl)line.getControl( FloatControl.Type.MASTER_GAIN); VolumeSlider vs = new VolumeSlider(volCtrl); gui.add( new JLabel(volCtrl.toString()) ); gui.add( vs.getVolume() ); System.out.println( " volCtrl.getValue() = " + volCtrl.getValue()); } catch (LineUnavailableException e) { e.printStackTrace(); } catch (IllegalArgumentException iaEx) { System.out.println(" " + iaEx); } } } return gui; } public static void main(String[] args) { Runnable r = new Runnable() { @Override public void run() { SoundMixer sm = new SoundMixer(); Component c = sm.getGui(); JOptionPane.showMessageDialog(null, c); } }; // Swing GUIs should be created and updated on the EDT // http://docs.oracle.com/javase/tutorial/uiswing/concurrency/initial.html SwingUtilities.invokeLater(r); }}class VolumeSlider { JSlider volume; VolumeSlider(final FloatControl volumeControl) { volume = new JSlider( (int) volumeControl.getMinimum() * 100, (int) volumeControl.getMaximum() * 100, (int) volumeControl.getValue() * 100); ChangeListener listener = new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { float val = volume.getValue() / 100f; volumeControl.setValue(val); System.out.println( "Setting volume of " + volumeControl.toString() + " to " + val); } }; volume.addChangeListener(listener); } public JSlider getVolume() { return volume; }}在这台Windows 7计算机上,我有两个控件,都来自“ Java Sound Audio Engine”。都不会影响当前的系统容量。
run:There are 4 mixer info objectsmixer name: Primary Sound Driver Line.Info: interface SourceDataLine supporting 8 audio formats, and buffers of at least 32 bytes java.lang.IllegalArgumentException: Unsupported control type: Master Gain Line.Info: interface Clip supporting 8 audio formats, and buffers of at least 32 bytes java.lang.IllegalArgumentException: Unsupported control type: Master Gainmixer name: Speakers (VIA High Definition Audio) Line.Info: interface SourceDataLine supporting 8 audio formats, and buffers of at least 32 bytes java.lang.IllegalArgumentException: Unsupported control type: Master Gain Line.Info: interface Clip supporting 8 audio formats, and buffers of at least 32 bytes java.lang.IllegalArgumentException: Unsupported control type: Master Gainmixer name: Java Sound Audio Engine Line.Info: interface SourceDataLine supporting 8 audio formats volCtrl.getValue() = 0.0 Line.Info: interface Clip supporting 8 audio formats, and buffers of 0 to 4194304 bytes volCtrl.getValue() = 0.0mixer name: Port Speakers (VIA High Definition ASetting volume of Master Gain with current value: 0.0 dB (range: -80.0 - 13.9794) to 0.0Setting volume of Master Gain with current value: 0.0 dB (range: -80.0 - 13.9794) to -0.41Setting volume of Master Gain with current value: 0.0 dB (range: -80.0 - 13.9794) to -0.68...
交换
FloatControl.Type.MASTER_GAIN了
FloatControl.Type.VOLUME看..没有控制。



