我正在尝试在我的虚拟音频电缆上播放 wav/mp3,我已经搜索了几个小时,但似乎找不到如何实现这一点。我已经能够以两种格式播放声音,但无法将其输出到“Line-1”而不是“扬声器”
任何有用的链接或示例代码将不胜感激。
最佳答案
获取所有Mixer
s的数组在当前平台上,您可以使用 AudioSystem#getMixerInfo
:
static void printAllMixerNames() {
for(Mixer.Info info : AudioSystem.getMixerInfo()) {
System.out.println(info.getName());
}
}
如果您的虚拟电缆可用,它将在阵列中。例如,在我的 Mac 上打印了以下内容:
Java Sound Audio Engine Built-in Input Soundflower (2ch) Soundflower (64ch) Pro Tools Aggregate I/O
(Soundflower is a virtual device.)
To get some specific Mixer
you unfortunately need to do String evaluation. So you need to discover its name, vendor, whatever, beforehand or give the user an option to pick one from a list.
static Mixer getMixerByName(String toFind) {
for(Mixer.Info info : AudioSystem.getMixerInfo()) {
if(toFind.equals(info.getName())) {
return AudioSystem.getMixer(info);
}
}
return null;
}
一旦您拥有了特定的Mixer
,您就可以从中获取Line
或AudioInputStream
。您可以通过 AudioSystem#getClip(Mixer.Info)
从中获取 Clip
.
I am trying to play a wav/mp3...
javax.sound.sampled
不支持 mp3
。 Alternatives can be found here.
关于java - 将混音器更改为在java中输出声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27026042/