如何停止来自Java应用程序的声音?

最佳答案

查看Sound API

要简单地使声音静音,您可以执行以下操作:

Port p = (Port)AudioSystem.getLine(Port.Info.SPEAKER);
p.open();

//print out volume
FloatControl vol = (FloatControl)p.getControl(FloatControl.Type.VOLUME);
System.out.println("Current Volume: " + vol.getValue());

//mute sound
BooleanControl mute = (BooleanControl)p.getControl(BooleanControl.Type.MUTE);
mute.setValue(true);

p.close();

07-24 09:15