Example #1
0
        /// <summary>
        /// Stop and reset the WaveOut device
        /// </summary>
        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");
                }

                // with function callbacks, waveOutReset will call OnDone,
                // and so PlaybackStopped must not be raised from the handler
                // we know playback has definitely stopped now, so raise callback
                if (callbackInfo.Strategy == WaveCallbackStrategy.FunctionCallback)
                {
                    RaisePlaybackStoppedEvent(null);
                }
            }
        }
Example #2
0
 /// <summary>
 /// Stop and reset the WaveOut device
 /// </summary>
 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
     }
 }