Created
October 18, 2016 13:50
-
-
Save LukasRypl/755a3d3692298180900c17d6b7d0b477 to your computer and use it in GitHub Desktop.
Audio devices as seen by javax.sound
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.sound.sampled.*; | |
import java.util.Arrays; | |
public class AudioSystemInfo { | |
public static void main(String[] args) { | |
System.out.println("Audio devices as seen by javax.sound:"); | |
// simpleMixerInfo(); | |
dumpMixers(); | |
} | |
private static void dumpLineInfo(String indent, Line.Info[] lineInfo) { | |
int numDumped = 0; | |
if (lineInfo != null) { | |
for (Line.Info info : lineInfo) { | |
if (info instanceof DataLine.Info) { | |
System.out.println(indent + "Line: " + info.toString()); | |
AudioFormat[] formats = ((DataLine.Info) info).getFormats(); | |
for (AudioFormat format : formats) { | |
System.out.println(indent + "\tFormat: " + format); | |
} | |
numDumped++; | |
} else if (info instanceof Port.Info) { | |
System.out.println(indent + "Port: " + info); | |
numDumped++; | |
} else { | |
System.out.println(indent + "Other: " + info.toString()); | |
} | |
} | |
} | |
if (numDumped == 0) { | |
System.out.println(indent + "none"); | |
} | |
} | |
private static void dumpMixers() { | |
Mixer.Info[] mixerInfo = AudioSystem.getMixerInfo(); | |
for (int i = 0; i < mixerInfo.length; i++) { | |
Mixer mixer = AudioSystem.getMixer(mixerInfo[i]); | |
System.out.println("\nMixer[" + i + "]:\t\"" | |
+ mixerInfo[i].getName() + '\"'); | |
System.out.println(" Description:\t" | |
+ mixerInfo[i].getDescription()); | |
System.out.println(" SourceLineInfo (e.g. speakers):"); | |
dumpLineInfo(" ", mixer.getSourceLineInfo()); | |
System.out.println(" TargetLineInfo (e.g. microphones):"); | |
dumpLineInfo(" ", mixer.getTargetLineInfo()); | |
} | |
} | |
private static void simpleMixerInfo() { | |
for (Mixer.Info mixer : AudioSystem.getMixerInfo()) { | |
System.out.println(String.format("\nMixer:\t %s \tDescription: %s", | |
mixer.getName(), | |
mixer.getDescription() | |
)); | |
Mixer m = AudioSystem.getMixer(mixer); | |
System.out.println(" Source lines: " + Arrays.asList(m.getSourceLineInfo())); | |
System.out.println(" Target lines: " + Arrays.asList(m.getTargetLineInfo())); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment