在特定的声音设备java上播放声音
我正在尝试做一些简单的事情。我想在给定的声音媒体上播放声音,而不是在默认媒体上播放 这是我最后一次尝试,在所有媒体上重复思考并播放声音。只有默认设备上的媒体才能播放某些内容。直接播放时,即使是默认设备也无法工作在特定的声音设备java上播放声音,java,audio,javasound,Java,Audio,Javasound,我正在尝试做一些简单的事情。我想在给定的声音媒体上播放声音,而不是在默认媒体上播放 这是我最后一次尝试,在所有媒体上重复思考并播放声音。只有默认设备上的媒体才能播放某些内容。直接播放时,即使是默认设备也无法工作 public void testSoundPLayer() throws Exception { AudioInputStream inputStream = AudioSystem.getAudioInputStream(Main.class.getResourceAsStre
public void testSoundPLayer() throws Exception {
AudioInputStream inputStream = AudioSystem.getAudioInputStream(Main.class.getResourceAsStream(Constants.SOUND_ALERT));
Mixer.Info[] mixerInfo = AudioSystem.getMixerInfo();
for(int i = 0; i < mixerInfo.length; i++)
{
Mixer.Info info = mixerInfo[i];
System.out.println(String.format("Name [%s] \n Description [%s]\n\n", info.getName(), info.getDescription()));
System.out.println(info.getDescription());
try
{
Clip clip = AudioSystem.getClip(info);
clip.open(inputStream);
clip.start();
}
catch (Throwable t)
{
System.out.println(t.toString());
}
Thread.sleep(2000L);
}
}
我愿意使用外部库,甚至可以更改默认的声卡。我只想要一个很好的方法在给定的声卡上播放声音,而不需要依赖操作系统的方法。这是一个遗憾,我犯了一个巨大的错误,我没有重新加载流。这意味着秒播放不起作用 有一个有效的例子
public void testSoundPLayer() throws Exception {
Mixer.Info[] mixerInfo = AudioSystem.getMixerInfo();
for(int i = 0; i < mixerInfo.length; i++)
{
AudioInputStream inputStream = AudioSystem.getAudioInputStream(Main.class.getResourceAsStream(Constants.SOUND_ALERT));
Mixer.Info info = mixerInfo[i];
System.out.println(String.format("Name [%s] \n Description [%s]\n\n", info.getName(), info.getDescription()));
System.out.println(info.getDescription());
try
{
Clip clip = AudioSystem.getClip(info);
clip.open(inputStream);
clip.start();
}
catch (Throwable t)
{
System.out.println(t.toString());
}
Thread.sleep(2000L);
}
}
要检查设备是否为输入或输出,请使用以下方法:
// Param for playback (input) device.
Line.Info playbackLine = new Line.Info(SourceDataLine.class);
// Param for capture (output) device.
Line.Info captureLine = new Line.Info(TargetDataLine.class);
private List<Mixer.Info> filterDevices(final Line.Info supportedLine) {
List<Mixer.Info> result = Lists.newArrayList();
ArrayList<Mixer.Info> infos = Lists.newArrayList(AudioSystem.getMixerInfo());
for (Mixer.Info info : infos) {
Mixer mixer = AudioSystem.getMixer(info);
if (mixer.isLineSupported(supportedLine)) {
result.add(info);
}
}
return result;
}
剪辑是Java声音的一部分,而不是JMF。我只是想有一个很好的方法来播放一个没有操作系统依赖的方法声波。你很困惑。剪辑就是它!实际上,我的最后一句话令人困惑。我想要一个很好的方法在给定的声卡上播放声音。我编辑这篇文章。