如何在许多设备上同时播放声音? [英] How to play sound in many devices at the same time?

查看:119
本文介绍了如何在许多设备上同时播放声音?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好


我想同时播放三个外部声卡中的声音,这意味着当我单击一个按钮时,我可以听到来自与三个声卡相关的三个扬声器的声音.我有一个功能,但它仅在一个设备中播放声音,它找到的第一个设备,我的意思是在此代码中,第一个设备是数字0,因此它在其中播放声音,但是如果您首先写设备号为1,它将在其中播放声音,作为结论,它只能在一个设备上播放声音,但不能同时在所有设备上运行.这是它的代码:

Hello


I want to play sound in three external sound cards at the same time,I mean when I click in a button I can hear sound from three speakers which are related to my three sound cards. I have a function but it plays sound only in one device,the first one it finds,I mean in this code the first device is number 0,so it play sound in it,but if you write device number 1 at first,it will play sound in it,as a conclusion it plays sound only in one device,it dont works for all the devices at the same time. This is its code:

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获得此名称的:



fileName is the name of the sound file I want to play,in my code I get this name from a 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();
    }



您能帮我找到解决方案吗????先感谢您.美好的一天.



Can you help me to find the solution please???? Thank you in advance. Good day.

推荐答案

尝试一下..

Try this..

System.Threading.Thread Thread1;
System.Threading.Thread Thread2;
System.Threading.Thread Thread3;

Thread1 = new System.Threading.Thread(this.playSound("aa.wav",0));
Thread2 = new System.Threading.Thread(this.playSound("bb.wav",1));
Thread3 = new System.Threading.Thread(this.playSound("cc.wav",2));

Thread1.Start();
Thread2.Start();
Thread3.Start();

public void playSound(string fileName,int i)
{
     WaveOut waveOut = new WaveOut();
     WaveFileReader waveReader = new WaveFileReader(fileName);
     waveOut.Init(waveReader);
     waveOut.DeviceNumber = i;
     waveOut.Play();
}


这篇关于如何在许多设备上同时播放声音?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆