1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.FloatControl;
import javax.sound.sampled.Port;
public class ControlSound2 {
static void ControleSonClient2(double d) {
Port lineOut;
try
{
if (AudioSystem.isLineSupported(Port.Info.LINE_OUT)) {
lineOut = (Port) AudioSystem.getLine(Port.Info.LINE_OUT);
lineOut.open();
} else if (AudioSystem.isLineSupported(Port.Info.HEADPHONE)) {
lineOut = (Port) AudioSystem.getLine(Port.Info.HEADPHONE);
lineOut.open();
} else if (AudioSystem.isLineSupported(Port.Info.SPEAKER)) {
lineOut = (Port) AudioSystem.getLine(Port.Info.SPEAKER);
lineOut.open();
} else {
System.out.println("Unable to get Output Port");
return;
}
FloatControl controlIn = (FloatControl)lineOut.getControl(FloatControl.Type.VOLUME);
float volume = 100 * (controlIn.getValue() / controlIn.getMaximum());
System.out.println("LINE_OUT : volume = " + volume);
controlIn.setValue((float)d / 100);
}
catch(final Exception e)
{
System.out.println(e + " LINE_OUT");
}
}
public static void main(String[] args) throws Exception
{
ControleSonClient2(50);
System.out.println("FIN");
}
} |
Partager