Api sound problem

Hi

I'm trying to use JAva sound API but I have an error on some computers with this code :

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.toString());

Mixer mixer = AudioSystem.getMixer(mixerInfos);

Line.Info[] targetLineInfos = mixer.getTargetLineInfo();

System.out.println("target infos : " + targetLineInfos.length);

for (int j = 0; j < targetLineInfos.length; j++) {

setVolume(targetLineInfos[j]);

}

}

}

static boolean setVolume(Line.Info lineInfo) {

try {

System.out.println(lineInfo);

Line line = AudioSystem.getLine(lineInfo);

System.out.println("open " + line.getLineInfo());

line.open();

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();

} catch (Exception e) {

System.out.println(e);

return false;

}

return true;

}

}

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...

Thanks for your ideas

[2180 byte] By [ZarMusea] at [2007-11-26 14:24:46]
# 1
This is a very strange "bug" because i can modify Speaker sound but not microphoneAny ideas ?
ZarMusea at 2007-7-8 2:17:32 > top of Java-index,Security,Cryptography...
# 2

First of, there is a small bug in your code

Mixer mixer = AudioSystem.getMixer(mixerInfos);

should be

Mixer mixer = AudioSystem.getMixer(mixerInfos[x])

with x being i but i cant use that here because it is used on this forum for italic :-)

According to the java tutorial it is normal that not all lines support the same controls.

http://java.sun.com/docs/books/tutorial/sound/controls.html

Citation:

A mixer can have various sorts of signal-processing controls on some or all of its lines. For example, a mixer used for audio capture might have an input port with a gain control, and target data lines with gain and pan controls. A mixer used for audio playback might have sample-rate controls on its source data lines. In each case, the controls are all accessed through methods of the Line interface.

Notice the use of the words 'can have' and 'might have' instead of 'has' in the text.

It's best to first query the line for it's supported controls before instanciating them

You can do that with the getControls() method.

Klaasa at 2007-7-8 2:17:32 > top of Java-index,Security,Cryptography...
# 3
Aha,there is no bug in your code, you just had the same problem as I when using '[' i ']'. it disappears in the code because it's used for the italics.Ok sorry for that :-)
Klaasa at 2007-7-8 2:17:32 > top of Java-index,Security,Cryptography...
# 4
Thanks.I need to control microphone volume, is there another solution ? Only Native Code ?
ZarMusea at 2007-7-8 2:17:32 > top of Java-index,Security,Cryptography...
# 5

I think you might want to concider using ports.

Check out the ports section on jsresources:

http://jsresources.sourceforge.net/faq_audio.html#sec_ports

(I tried their SystemMixer example and it seems to be possible to change the volume of my line-in, although the gui really seems a bit buggy on my computer:-) )

Klaasa at 2007-7-8 2:17:32 > top of Java-index,Security,Cryptography...
# 6
Do you have your example of this code ? Can you copy/paste it please ?Tanks a lot
ZarMusea at 2007-7-8 2:17:32 > top of Java-index,Security,Cryptography...