我想同时在三个外部声卡中播放声音,我的意思是当我点击一个按钮时,我可以听到三个与我的三个声卡相关的扬声器的声音。我有一个功能,但它只在一个设备中播放声音,它找到的第一个设备,我的意思是在这段代码中第一个设备是数字 0,所以它在其中播放声音,但是如果你首先写设备号 1,它会在其中播放声音,作为结论,它仅在一个设备上播放声音,它不能同时适用于所有设备。这是它的代码:
public void playAllAvailableDevices()
{
//create a new class for each wav file & output etc.
WaveOut waveOut1 = new WaveOut();
WaveFileReader waveReader1 = new WaveFileReader(fileName);
WaveOut waveOut2 = new WaveOut();
WaveFileReader waveReader2 = new WaveFileReader(fileName);
WaveOut waveOut3 = new WaveOut();
WaveFileReader waveReader3 = new WaveFileReader(fileName);
switch (waveOutDevices)
{
case 1:
waveOut1.Init(waveReader1);
waveOut1.DeviceNumber = 0;
waveOut1.Play();
break;
case 2:
waveOut1.Init(waveReader1);
waveOut1.DeviceNumber = 0;
waveOut1.Play();
waveOut2.Init(waveReader2);
waveOut2.DeviceNumber = 1;
waveOut2.Play();
break;
case 3:
waveOut1.Init(waveReader1);
waveOut1.DeviceNumber = 0;
waveOut1.Play();
waveOut2.Init(waveReader2);
waveOut2.DeviceNumber = 1;
waveOut2.Play();
waveOut3.Init(waveReader3);
waveOut3.DeviceNumber = 2;
waveOut3.Play();
break;
}}
fileName 是我要播放的声音文件的名称,在我的代码中,我从 darabase 获取此名称:
private void btnAlarm1_Click(object sender, EventArgs e)
{
OdbcConnection cn = new OdbcConnection("DSN=cp1");
cn.Open();
OdbcCommand cmd1 = new OdbcCommand("select chemin from alarme where code_alarme=41", cn);
cmd1.Connection = cn;
fileName = cmd1.ExecuteScalar().ToString();
wave = new WaveOut();
playAllAvailableDevices();
}
你能帮我找到解决办法吗????先感谢您。再会。