468,765 Members | 1,233 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,765 developers. It's quick & easy.

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:
Expand|Select|Wrap|Line Numbers
  1. public void playAllAvailableDevices()
  2. {
  3. //create a new class for each wav file & output etc.
  4. WaveOut waveOut1 = new WaveOut();
  5. WaveFileReader waveReader1 = new WaveFileReader(fileName);
  6. WaveOut waveOut2 = new WaveOut();
  7. WaveFileReader waveReader2 = new WaveFileReader(fileName);
  8. WaveOut waveOut3 = new WaveOut();
  9. WaveFileReader waveReader3 = new WaveFileReader(fileName);
  10.  
  11. switch (waveOutDevices)
  12. {
  13. case 1: 
  14. waveOut1.Init(waveReader1);
  15. waveOut1.DeviceNumber = 0;
  16. waveOut1.Play();
  17. break;
  18. case 2: 
  19. waveOut1.Init(waveReader1);
  20. waveOut1.DeviceNumber = 0;
  21. waveOut1.Play();
  22.  
  23. waveOut2.Init(waveReader2);
  24. waveOut2.DeviceNumber = 1;
  25. waveOut2.Play();
  26. break;
  27. case 3:
  28. waveOut1.Init(waveReader1);
  29. waveOut1.DeviceNumber = 0;
  30. waveOut1.Play();
  31.  
  32. waveOut2.Init(waveReader2);
  33. waveOut2.DeviceNumber = 1;
  34. waveOut2.Play();
  35.  
  36. waveOut3.Init(waveReader3);
  37. waveOut3.DeviceNumber = 2;
  38. waveOut3.Play();
  39. break;
  40. }}
  41.  
fileName is the name of the sound file I want to play,in my code I get this name from a darabase:
Expand|Select|Wrap|Line Numbers
  1. private void btnAlarm1_Click(object sender, EventArgs e)
  2.     {
  3.  
  4.         OdbcConnection cn = new OdbcConnection("DSN=cp1");
  5.         cn.Open();
  6.         OdbcCommand cmd1 = new OdbcCommand("select chemin from alarme where code_alarme=41", cn);
  7.         cmd1.Connection = cn;
  8.         fileName = cmd1.ExecuteScalar().ToString();
  9.         wave = new WaveOut();
  10.         playAllAvailableDevices();
  11.     }
  12.  
Can you help me to find the solution please???? Thank you in advance. Good day.
May 15 '11 #1
1 2305
Brosert
57
Where and how is waveOutDevices (passed to your switch statement) set?

Currently, it appears that within playAllAvailableDevices
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.
May 18 '11 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Bill Dandreta | last post: by
1 post views Thread by svpsiva | last post: by
reply views Thread by yuen | last post: by
reply views Thread by seo gang ho | last post: by
1 post views Thread by Lam | last post: by
10 posts views Thread by CM | last post: by
1 post views Thread by anuvanand1 | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.