Re: Java API sound
<boutreau.adrien@gmail.com> wrote in message
news:1168251053.443856.212310@11g2000cwr.googlegroups.com...
Hi
I'm trying to use JAva sound API but I have an error on some computers
with this code :
[code snipped]
Error :
java.lang.IllegalArgumentException: Unsupported control type: Mute
Is there a solution to control it ? Because I can control the Speaker
Sound but not microphone...
It looks basically like certain lines don't support some of the controls
you want. I've modified your code as follows:
<SSCCE>
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.BooleanControl;
import javax.sound.sampled.FloatControl;
import javax.sound.sampled.Line;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.Mixer;
public class ControlTest {
public static void main(String[] args) throws LineUnavailableException,
InterruptedException {
Mixer.Info[] mixerInfos = AudioSystem.getMixerInfo();
for (int i = 0; i < mixerInfos.length; i++) {
System.out.println("AudioSystem info Name:" + mixerInfos[i].toString());
Mixer mixer = AudioSystem.getMixer(mixerInfos[i]);
Line.Info[] targetLineInfos = mixer.getTargetLineInfo();
System.out.println("target infos : " + targetLineInfos.length);
for (int j = 0; j < targetLineInfos.length; j++) {
try {
setVolume(targetLineInfos[j]);
}
catch (IllegalArgumentException e) {
continue;
}
}
}
}
static void setVolume(Line.Info lineInfo) throws LineUnavailableException {
System.out.println(lineInfo);
Line line = AudioSystem.getLine(lineInfo);
System.out.println(" open " + line.getLineInfo());
line.open();
line.getControls(); /*SPECIAL LINE*/
BooleanControl muteControl =
(BooleanControl)line.getControl(BooleanControl.Type.MUTE);
System.out.println(" mute " + muteControl);
muteControl.setValue(true);
FloatControl control =
(FloatControl)line.getControl(FloatControl.Type.VOLUME);
control.setValue(control.getMinimum());
System.out.println(" val " + control.getValue());
FloatControl controlp =
(FloatControl)line.getControl(FloatControl.Type.MASTER_GAIN);
controlp.setValue(control.getMinimum());
System.out.println(" val " + controlp.getValue());
line.close();
}
}
</SSCCE>
Notice the line marked /*SPECIAL LINE*/. If you set a breakpoint there, you
can look at the return value of line.getControls() to see what controls a
particular line supports.
- Oliver