Exemplo n.º 1
0
 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();
 }
Exemplo n.º 2
0
 private void DisposeWave()
 {
     if (stream != null)
     {
         stream.Dispose();
         stream = null;
     }
 }
Exemplo n.º 3
0
 //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;
         }
     }
 }
Exemplo n.º 4
0
 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;
     }
 }
Exemplo n.º 5
0
 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;
     }
 }
Exemplo n.º 6
0
        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;
            }
        }
Exemplo n.º 7
0
 /// <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;
     }
 }
Exemplo n.º 8
0
 /// <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;
     }
 }