/// <summary> /// Resumes playing after a pause from the same position. /// </summary> void Resume() { if (PlaybackState == PlaybackState.Paused) { MultimediaResult result; lock (_waveOutLock) { result = WaveInterop.waveOutRestart(_hWaveOut); } if (result != MultimediaResult.NoError) { throw new MultimediaException(result, "waveOutRestart"); } PlaybackState = PlaybackState.Playing; } }
/// <summary> /// Pauses the audio. /// </summary> internal void Pause() { if (PlaybackState == PlaybackState.Playing) { PlaybackState = PlaybackState.Paused; // set this here to avoid a deadlock problem with some drivers MultimediaResult result; lock (_waveOutLock) { result = WaveInterop.waveOutPause(_hWaveOut); } if (result != MultimediaResult.NoError) { throw new MultimediaException(result, "waveOutPause"); } } }
/// <summary> /// Gets the position of the waveout stream from the WindowsAPI. /// </summary> /// <returns></returns> internal uint GetPosition() { lock (_waveOutLock) { var multimediaTime = new MultimediaTime(); multimediaTime.wType = MultimediaTime.TIME_BYTES; MultimediaException.Try(WaveInterop.waveOutGetPosition(_hWaveOut, ref multimediaTime, Marshal.SizeOf(multimediaTime)), "waveOutGetPosition"); // if (multimediaTime.wType != MultimediaTime.TIME_BYTES) // throw new Exception(string.Format("waveOutGetPosition: wType -> Expected {0}, Received {1}", // MultimediaTime.TIME_BYTES, multimediaTime.wType)); return(multimediaTime.cb); } }
/// <summary> /// Stops and resets the WaveOut device. /// </summary> internal void Stop() { if (PlaybackState != PlaybackState.Stopped) { // in the call to waveOutReset with function callbacks some drivers // will block here until done() is called for every buffer PlaybackState = PlaybackState.Stopped; // set this here to avoid a problem with some drivers MultimediaResult result; lock (_waveOutLock) { result = WaveInterop.waveOutReset(_hWaveOut); } if (result != MultimediaResult.NoError) { throw new MultimediaException(result, "waveOutReset"); } _callbackEvent.Set(); // give the thread a kick to force it to exit. } }