final Properties prop = new Properties();
loadSoundProperties(prop);
final Map<String, AudioFormat> formatMap = new TreeMap<String, AudioFormat>();
final Map<String, String> fileFormatMap = new TreeMap<String, String>();
final Mixer defaultMixer = TESTPLAY_SAMPLES? AudioSystem.getMixer(null): null;
// get sound library filepath
final String soundBase = prop.getProperty("soundbase", "data/sounds");
// read all load-permitted sounds listed in properties
// from soundfile into cache map
for (final Entry<String, String> entry : ((Map<String, String>) (Map<?,?>) prop).entrySet()) {
if (isValidEntry(entry.getKey(), entry.getValue())) {
final String name = entry.getKey().substring(4);
String filename = entry.getValue();
final int pos = filename.indexOf(',');
if (pos > -1) {
filename = filename.substring(0, pos);
}
try {
final InputStream is = CheckSounds.class.getClassLoader().getResourceAsStream(
soundBase + "/" + filename);
final AudioInputStream ais = AudioSystem.getAudioInputStream(is);
final AudioFormat format = ais.getFormat();
final String formatString = format.toString();
if (TESTPLAY_SAMPLES) {
// testplay the sound
final DataLine.Info info = new DataLine.Info(Clip.class, format);
if (defaultMixer.isLineSupported(info)) {
AudioInputStream playStream = ais;
final AudioFormat defaultFormat = new AudioFormat(
format.getSampleRate(), 16, 1, false, true);
if (AudioSystem.isConversionSupported(
defaultFormat, format)) {
playStream = AudioSystem.getAudioInputStream(
defaultFormat, ais);
} else {
System.out.println("conversion not supported (to "
+ defaultFormat + ")");
}
System.out.println("testplaying " + name + " "
+ playStream.getFormat());
final Clip line = (Clip) defaultMixer.getLine(info);
line.open(playStream);
line.loop(2);
final TestLineListener testListener = new TestLineListener();
line.addLineListener(testListener);
while (testListener.active) {
Thread.yield();
}
line.close();
}
}
fileFormatMap.put(name, formatString);
if (!formatMap.containsKey(formatString)) {
formatMap.put(formatString, format);
}
} catch (final UnsupportedAudioFileException e) {
System.out.println(name
+ " cannot be read, the file format is not supported");
}
}
}
final Mixer.Info[] mixerList = AudioSystem.getMixerInfo();
final int[] width = new int[mixerList.length];
System.out.println("\n\n--- Result ---\n");
System.out.println("installed mixer: ");
for (int i = 0; i < mixerList.length; i++) {
final Mixer.Info mixer = mixerList[i];
width[i] = Math.max(mixer.getName().length(),
"unsupported".length());
System.out.println(mixer.getName() + " - " + mixer.getDescription());
}
System.out.println("Default: "
+ AudioSystem.getMixer(null).getMixerInfo().getName());
System.out.println("\n");
System.out.println(formatMap.size()
+ " audio formats\nThe maximum available lines for the format is in brackets.");
for (int i = 0; i < mixerList.length; i++) {
System.out.print(getString(mixerList[i].getName(), width[i], ' ')
+ " | ");
}
System.out.println("Format");
for (int i = 0; i < mixerList.length; i++) {
System.out.print(getString("", width[i], '-') + "-+-");
}
System.out.println("---------------------");
for (final Map.Entry<String, AudioFormat> it_FM : formatMap.entrySet()) {
String key = it_FM.getKey();
final DataLine.Info info = new DataLine.Info(Clip.class, it_FM.getValue());
for (int i = 0; i < mixerList.length; i++) {
final Mixer mixer = AudioSystem.getMixer(mixerList[i]);
final boolean supported = mixer.isLineSupported(info);
StringBuilder stringBuilder = new StringBuilder();
if (supported) {
stringBuilder.append(" ");
} else {
stringBuilder.append("un");
}
stringBuilder.append("supported (");
stringBuilder.append(mixer.getMaxLines(info));
stringBuilder.append(")");
System.out.print(getString(stringBuilder.toString(),
width[i], ' ') + " | ");
}