public void PlaySound(string name, Action done = null) { FileStream ms = File.OpenRead(_soundLibrary[name]); var rdr = new Mp3FileReader(ms); WaveStream wavStream = WaveFormatConversionStream.CreatePcmStream(rdr); var baStream = new BlockAlignReductionStream(wavStream); var waveOut = new WaveOut(WaveCallbackInfo.FunctionCallback()); waveOut.Init(baStream); waveOut.Play(); var bw = new BackgroundWorker(); bw.DoWork += (s, o) => { while (waveOut.PlaybackState == PlaybackState.Playing) { Thread.Sleep(100); } waveOut.Dispose(); baStream.Dispose(); wavStream.Dispose(); rdr.Dispose(); ms.Dispose(); if (done != null) done(); }; bw.RunWorkerAsync(); }
private void DisposeWave() { if (stream != null) { stream.Dispose(); stream = null; } }
//Function to dispose the current mp3 file private void DisposeWave() { if (output != null) { if (output.PlaybackState == NAudio.Wave.PlaybackState.Playing) { output.Dispose(); output.Stop(); } if (stream != null) { stream.Dispose(); stream = null; } } }
public static void disposeWave() { if (output != null) { if (output.PlaybackState == NAudio.Wave.PlaybackState.Playing) { output.Stop(); } output.Dispose(); } if (stream != null) { stream.Dispose(); stream = null; } }
public void MP3CloseFile() { if (output != null) { if (output.PlaybackState == NAudio.Wave.PlaybackState.Playing) { output.Stop(); } output.Dispose(); output = null; } if (stream != null) { stream.Dispose(); stream = null; } }
public void DisposeWave() { try { if (output != null) { if (output.PlaybackState == NAudio.Wave.PlaybackState.Playing) { output.Stop(); output.Dispose(); output = null; } } if (stream != null) { stream.Dispose(); stream = null; } if (outputLocal != null) { if (outputLocal.PlaybackState == NAudio.Wave.PlaybackState.Playing) { outputLocal.Stop(); outputLocal.Dispose(); outputLocal = null; } } if (stream2 != null) { stream2.Dispose(); stream2 = null; } } catch (NAudio.MmException) { throw; } }
/// <summary> /// Releases unmanaged and - optionally - managed resources. /// </summary> /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param> protected virtual void Dispose(bool disposing) { if (!_disposed) { if (disposing) { if (output != null) { output.Stop(); output.Dispose(); output = null; } if (reduce != null) { reduce.Dispose(); reduce = null; } } _disposed = true; } }
/// <summary> /// Stops play back and relise all resorces. /// </summary> public void stop() { try { if (output != null) { if (output.PlaybackState == NAudio.Wave.PlaybackState.Playing) { output.Stop(); } output.Dispose(); output = null; } if (stream != null) { stream.Dispose(); stream = null; } } catch (Exception) { stream = null; } }