【发布时间】:2017-05-02 00:21:56
【问题描述】:
当我按下按钮时,netbeans 本身说:“线程中的异常“AWT-EventQueue-0”java.lang.IllegalArgumentException:没有行匹配接口 TargetDataLine 支持格式 PCM_SIGNED 44100.0 Hz,16 位,单声道,2 字节/帧, 支持大端序。” 当线路不支持时,它应该会弹出一条错误消息说“线路不支持”。相反,什么也没有发生。 我该怎么办?
public class Ouvir extends NewJFrame{
AudioFormat audioFormat;
TargetDataLine targetDataLine;
TargetDataLine line;
void captureAudio(){
Listen.setEnabled(false);
try{
audioFormat = getAudioFormat();
DataLine.Info info = new DataLine.Info(TargetDataLine.class, audioFormat);
line = (TargetDataLine) AudioSystem.getLine(info);
AudioSystem.getLine(info);
if (!AudioSystem.isLineSupported(info)) {
String error = "Line not supported";
JOptionPane.showMessageDialog(null,error,"+",JOptionPane.ERROR_MESSAGE);
line.close();
}
line.open();
line.start();
}
catch (LineUnavailableException e) {}
}
void stopCapture(){
if(line != null)
{
line.stop();
line.close();
}
if(!Stop.getModel().isPressed())
{
line.stop();
line.close();
}
}
private AudioFormat getAudioFormat(){
return new AudioFormat(44100,16,1,true,true);
}
}
【问题讨论】:
-
在测试它是否受支持之前,您会获得
AudioLine -
我该如何解决这个问题?不太明白
-
你需要在
AudioSystem.getLine(info)之前调用AudioSystem.isLineSupported(info),否则你怎么知道是否支持
标签: java