nicole castel

nicole castel

  • NA
  • 208
  • 47.8k

Play sound in a loop

Jun 17 2011 4:40 PM
 Hello 

I have a play function wich plays sound file in all the card soundes related to my pc but when try to play a sound file in a loop,the function play sound in a loop but it stops playing it in alla available devices,this is my playsoud function:

public void PlaySoundInDevice(int deviceNumber, string fileName)
        {
            if (outputDevices.ContainsKey(deviceNumber))
            {
                outputDevices[deviceNumber].WaveOut.Dispose();
                outputDevices[deviceNumber].WaveStream.Dispose();
            }

            var waveOut = new WaveOut();
            waveOut.DeviceNumber = deviceNumber;
            WaveStream waveReader = new WaveFileReader(fileName);
            outputDevices[deviceNumber] = new PlaybackSession { WaveOut = waveOut, WaveStream = waveReader };
           // LoopStream loop = new LoopStream(waveReader);
           // waveOut = new WaveOut();
           // waveOut.Init(loop);
            waveOut.Init(waveReader);
            waveOut.Play();
            // hold onto the WaveOut and  WaveStream so we can dispose them later
         

        }

        private Dictionary<int, PlaybackSession> outputDevices = new Dictionary<int, PlaybackSession>();

        class PlaybackSession
        {
            public IWavePlayer WaveOut { get; set; }
            public WaveStream WaveStream { get; set; }
        }
        private void DisposeAll()
        {
            foreach (var playbackSession in outputDevices.Values)
            {
                playbackSession.WaveOut.Dispose();
                playbackSession.WaveStream.Dispose();
            }
        }
        public void PlayInAllAvailableDevices(string fileName)
        {
            int waveOutDevices = WaveOut.DeviceCount;
            for (int n = 0; n < waveOutDevices; n++)
            {
                PlaySoundInDevice(n, fileName);
            }
   Please can you give me an idea or a code ? thank you in advance ,good day 


Answers (4)