Using Java, I'm trying to record sound from the default microphone and show the current volume and mute status (as set at OS level, not interested in checking bytes if possible). So far, I can get the TargetDataLine and record to it using the following code:
TargetDataLine line = (TargetDataLine) AudioSystem.getLine(new DataLine.Info(TargetDataLine.class, formato));
This works great on Windows, line being the default microphone selected using the OS.
Right now, to get volume/mute controls I have the following code:
Mixer.Info[] mixerInfos = AudioSystem.getMixerInfo();
for (Mixer.Info mixerInfo : mixerInfos) {
Mixer mixer = AudioSystem.getMixer(mixerInfo);
if (mixer.getMaxLines(Port.Info.MICROPHONE) > 0) {
System.out.println("-------------");
System.out.println(mixerInfo);
Port line = (Port) mixer.getLine(Port.Info.MICROPHONE);
line.open();
Line.Info[] targets = mixer.getTargetLineInfo();
Control[] controls = line.getControls();
for (Control control : controls) {
if (control instanceof CompoundControl) {
Control[] subControls = ((CompoundControl) control).getMemberControls();
for (Control subControl : subControls) {
System.out.println(subControl);
}
} else {
System.out.println(control);
}
}
System.out.println("-----------");
}
}
There are 2 microphones in my setup and I haven't found a way of knowing which is the default one (right now it is the second one in the array).
Tried Line port = AudioSystem.getLine(Port.Info.MICROPHONE);
and it is returning the first one available (and it is not the default in this instance).
So, any way to get the default microphone port that relates to the TargetDataLine obtained?
Thanks!
TargetDataLIne
as I stated in my question and yes, I do that to record audio. I need to get the volume level and for that I need the port that belongs to thatTargetDataLine
so I can get its controls. – Lioness