I'm currently trying to use JSliderin Javato manage the bulk of my PC. So far, I have been able to find the port of the main PC speaker. However, I do not know how to successfully call it and run the getValue () or setValue () method.
I used the following code to search all my audio devices on my PC:
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();
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();
}
}
}
}
How can I gain control over my dynamics and change the value?
I used this site for help.
UPDATE
, , . Java " " (, ). JSlider Change Listener.
:
Port SPEAKER;
FloatControl volCtrl;
try {
Mixer mixer = AudioSystem.getMixer(null);
SPEAKER = (Port)mixer.getLine(Port.Info.SPEAKER);
SPEAKER.open();
volCtrl = (FloatControl) SPEAKER.getControl(
FloatControl.Type.VOLUME);
} catch (Exception e) {
System.out.println("Failed trying to find LINE_IN"
+ " VOLUME control: exception = " + e);
}
, , " ...". volCtrl ? , SPEAKER?