2013-04-08 242 views
0

我在电脑中连接了多个声卡。在Java中选择用于播放声音的声卡

现在,我想通过不是默认声卡设备的声卡播放声音。 Java Sound API可能吗?我怎样才能做到这一点?

谢谢!

+0

请尝试此链接:http://www.developerfusion.com/article/84314/wired-for-sound/ – 2013-04-08 08:04:26

+0

谢谢,但这只显示如何在默认播放声音线,但不是如何在另一个声音设备上播放声音 – Soccertrash 2013-04-08 08:29:18

回答

0
import javax.sound.sampled.* 

AudioInputStream audioIn = AudioSystem.getAudioInputStream(url); 

Mixer.Info[] arrMixerInfo = AudioSystem.getMixerInfo(); 

// Get a sound clip resource. 
Clip clip = AudioSystem.getClip(arrMixerInfo[1]); 

// Open audio clip and load samples from the audio input stream. 
clip.open(audioIn); 
clip.start(); 
clip.drain(); 
clip.close(); 

arrMixerInfo[0]表示默认声卡。此代码只能播放.wav文件

+0

这不完全正确。我只有默认声卡和虚拟电缆。现在,如果我从AudioSystem.getMixerInfo()中打印出前三个设备,我会得到以下输出: (1):主声音驱动程序 (2):扬声器(Conexant 20672 SmartAudio HD)和(3) CABLE- A输入(VB-音频电缆A) 虽然第二个声音驱动程序是默认驱动程序(因此与第一个驱动程序相同) – 2015-01-14 13:41:55