简体   繁体   English

使用 Java 声音 API 捕获声音时遇到 LineUnavailableException

[英]Encountered LineUnavailableException when capturing sound with Java Sound API

I am using Java Sound API to capture sound on a Windows machine by reading data from a TargetDataLine.我正在使用 Java Sound API 通过从 TargetDataLine 读取数据来捕获 Windows 机器上的声音。 It works fine if I open a line, read data from the line and then close it.如果我打开一行,从该行读取数据然后关闭它,它工作正常。 However, If I reopen it once closed, I will get a LineUnavailableException.但是,如果我在关闭后重新打开它,我会得到一个 LineUnavailableException。 Can someone explain to me what is going on?有人可以向我解释发生了什么吗? If I want to record multiple sound clips, one after another, say repeating this: start -------> record ---------> stop several times, how can I do it?如果我想一个接一个地录制多个声音片段,说重复这个:开始------->录制-------->停止几次,我该怎么做?

Thanks谢谢

The API says: API说:

Some lines, once closed, cannot be reopened.有些线路一旦关闭,就无法重新打开。 Attempts to reopen such a line will always result in a LineUnavailableException .尝试重新打开此类行将始终导致LineUnavailableException

I think the reason they say "some lines" is that it depends on external factors pertaining to the particular system.我认为他们说“一些线”的原因是它取决于与特定系统有关的外部因素。

You will need to create a line for each additional recording, it seems.看来,您需要为每个额外的录音创建一条线。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM