How to play sound in many devices at the same time?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nicolecastel
    New Member
    • Mar 2011
    • 17

    How to play sound in many devices at the same time?

    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:
    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 is the name of the sound file I want to play,in my code I get this name from a darabase:
    Code:
    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.
  • Brosert
    New Member
    • Jul 2008
    • 57

    #2
    Where and how is waveOutDevices (passed to your switch statement) set?

    Currently, it appears that within playAllAvailabl eDevices
    you switch based on a variable that is never set.
    Further, there is only 1 pass through the function, so only 1 device will ever play.

    Comment

    Working...