Java Sound refresh Lines list after attaching a microphone

前端 未结 2 1021
情书的邮戳
情书的邮戳 2021-01-12 18:58

I have a simple capture/playback Swing app that has to detect if there is no appropriate microphone attached to the computer and warn the user. After a lot of fiddling aroun

2条回答
  •  离开以前
    2021-01-12 19:41

    Posting the code that throws the exception might help.

    I'm assuming you are only using the Port.Info to detect the presence of a microphone then getting a Dataline to record:

    TargetDataLine dataLine = (TargetDataLine) AudioSystem.getLine(new DataLine.Info(TargetDataLine.class, audioFormat));                       
    dataLine.open();
    dataLine.start();               
    dataLine.read(b, offset, len);
    

    Note that you might still get a similar exception when disconnecting the microphone if the microphone is physically disconnected between the time you check for presence and the time you try to get the Dataline to record but connecting the microhpone should not be a problem.

提交回复
热议问题