AudioFormat formatTmp = null;
TargetDataLine lineTmp = null;
String filePath = fileTextField.getText();
AudioInputStream din = null;
AudioInputStream outDin = null;
PCM2PCMConversionProvider conversionProvider = new PCM2PCMConversionProvider();
boolean isMicrophone = false;
if (filePath == null || filePath.equals("") || isMatching) {
formatTmp = getFormat(); // Fill AudioFormat with the wanted
// settings
DataLine.Info info = new DataLine.Info(TargetDataLine.class,
formatTmp);
lineTmp = (TargetDataLine) AudioSystem.getLine(info);
isMicrophone = true;
} else {
AudioInputStream in;
if (filePath.contains("http")) {
URL url = new URL(filePath);
in = AudioSystem.getAudioInputStream(url);
} else {
File file = new File(filePath);
in = AudioSystem.getAudioInputStream(file);
}
AudioFormat baseFormat = in.getFormat();
System.out.println(baseFormat.toString());
AudioFormat decodedFormat = new AudioFormat(
AudioFormat.Encoding.PCM_SIGNED,
baseFormat.getSampleRate(), 16, baseFormat.getChannels(),
baseFormat.getChannels() * 2, baseFormat.getSampleRate(),
false);
din = AudioSystem.getAudioInputStream(decodedFormat, in);
if (!conversionProvider.isConversionSupported(getFormat(),
decodedFormat)) {
System.out.println("Conversion is not supported");
}
System.out.println(decodedFormat.toString());
outDin = conversionProvider.getAudioInputStream(getFormat(), din);
formatTmp = decodedFormat;
DataLine.Info info = new DataLine.Info(TargetDataLine.class,
formatTmp);
lineTmp = (TargetDataLine) AudioSystem.getLine(info);