NAudio.Wave.WaveOutEvent.Stop C# (CSharp) Method

Stop() public method

Stop and reset the WaveOut device
public Stop ( ) : void
return void
        public void Stop()
        {
            if (playbackState != PlaybackState.Stopped)
            {
                // in the call to waveOutReset with function callbacks
                // some drivers will block here until OnDone is called
                // for every buffer
                playbackState = PlaybackState.Stopped; // set this here to avoid a problem with some drivers whereby 
                MmResult result;
                lock (waveOutLock)
                {
                    result = WaveInterop.waveOutReset(hWaveOut);
                }
                if (result != MmResult.NoError)
                {
                    throw new MmException(result, "waveOutReset");
                }
                callbackEvent.Set(); // give the thread a kick, make sure we exit
            }
        }

Usage Example

Example #1
0
        public static void PlayFromFile(string filename, int frequency)
        {
            using (
               FileStream stream = new FileStream(filename, FileMode.Open))
            {
                var waveFormat = WaveFormat.CreateMuLawFormat(frequency * 2, 1);
                var reader = new NAudio.Wave.RawSourceWaveStream(stream, waveFormat);
                using (WaveStream convertedStream = WaveFormatConversionStream.CreatePcmStream(reader))
                {

                    convertedStream.Seek(0, 0);
                    WaveOutEvent player = new WaveOutEvent();
                    WaveChannel32 volumeStream = new WaveChannel32(convertedStream);
                    player.Init(volumeStream);
                    player.Play();

                    while (player.PlaybackState == PlaybackState.Playing)
                    {
                        System.Threading.Thread.Sleep(100);
                        var input = Console.ReadKey();
                        if (input.KeyChar > 1) ;
                        {
                            player.Stop();
                        }

                    }
                }
            }
        }
All Usage Examples Of NAudio.Wave.WaveOutEvent::Stop