Можно получить все поддерживаемые Lines
и их AudioFormats
напрямую.Я сделал это для SourceDataLines
по умолчанию Mixer
в системе, и вы можете легко отредактировать код, чтобы получить любой тип Lines
и AudioFormats
, поддерживаемый любым Mixer
.
Mixer mixer = AudioSystem.getMixer(null); // default mixer
mixer.open();
System.out.printf("Supported SourceDataLines of default mixer (%s):\n\n", mixer.getMixerInfo().getName());
for(Line.Info info : mixer.getSourceLineInfo()) {
if(SourceDataLine.class.isAssignableFrom(info.getLineClass())) {
SourceDataLine.Info info2 = (SourceDataLine.Info) info;
System.out.println(info2);
System.out.printf(" max buffer size: \t%d\n", info2.getMaxBufferSize());
System.out.printf(" min buffer size: \t%d\n", info2.getMinBufferSize());
AudioFormat[] formats = info2.getFormats();
System.out.println(" Supported Audio formats: ");
for(AudioFormat format : formats) {
System.out.println(" "+format);
// System.out.printf(" encoding: %s\n", format.getEncoding());
// System.out.printf(" channels: %d\n", format.getChannels());
// System.out.printf(format.getFrameRate()==-1?"":" frame rate [1/s]: %s\n", format.getFrameRate());
// System.out.printf(" frame size [bytes]: %d\n", format.getFrameSize());
// System.out.printf(format.getSampleRate()==-1?"":" sample rate [1/s]: %s\n", format.getSampleRate());
// System.out.printf(" sample size [bit]: %d\n", format.getSampleSizeInBits());
// System.out.printf(" big endian: %b\n", format.isBigEndian());
//
// Map<String,Object> prop = format.properties();
// if(!prop.isEmpty()) {
// System.out.println(" Properties: ");
// for(Map.Entry<String, Object> entry : prop.entrySet()) {
// System.out.printf(" %s: \t%s\n", entry.getKey(), entry.getValue());
// }
// }
}
System.out.println();
} else {
System.out.println(info.toString());
}
System.out.println();
}
mixer.close();
Я получаю вывод, подобный этому:
interface SourceDataLine supporting 8 audio formats, and buffers of at least 32 bytes
max buffer size: -1
min buffer size: 32
Supported Audio formats:
PCM_UNSIGNED unknown sample rate, 8 bit, mono, 1 bytes/frame,
PCM_SIGNED unknown sample rate, 8 bit, mono, 1 bytes/frame,
PCM_SIGNED unknown sample rate, 16 bit, mono, 2 bytes/frame, little-endian
PCM_SIGNED unknown sample rate, 16 bit, mono, 2 bytes/frame, big-endian
PCM_UNSIGNED unknown sample rate, 8 bit, stereo, 2 bytes/frame,
PCM_SIGNED unknown sample rate, 8 bit, stereo, 2 bytes/frame,
PCM_SIGNED unknown sample rate, 16 bit, stereo, 4 bytes/frame, little-endian
PCM_SIGNED unknown sample rate, 16 bit, stereo, 4 bytes/frame, big-endian
interface Clip supporting 8 audio formats, and buffers of at least 32 bytes