Exemple #1
0
        public void OpenFile(string path)
        {
            Stop();

            if (ActiveStream != null)
            {
                sampleReset = 0;
                SelectionBegin = TimeSpan.Zero;
                SelectionEnd = TimeSpan.Zero;
                ChannelPosition = 0;
            }

            StopAndCloseStream();

            if (System.IO.File.Exists(path))
            {
                try
                {
                    waveOutDevice = new WaveOutEvent()
                    {
                        DesiredLatency = 100
                    };


                    this.inputStream = new AudioFileReaderRB(path);
                    this.ActiveStream = this.inputStream.ReaderStream;
                    sampleAggregator = new SampleAggregator(fftDataSize);

                    Equalizer eq = new Equalizer(inputStream, this.bands);
                    eq.Sample += eq_Sample;
                    waveOutDevice.Init(eq);
                    ChannelLength = inputStream.TotalTime.TotalSeconds;
                    FileTag = TagLib.File.Create(path);
                    //GenerateWaveformData(path);
                    CanPlay = true;
                }
                catch
                {
                    ActiveStream = null;
                    CanPlay = false;
                }
            }
        }
Exemple #2
0
 private void StopAndCloseStream()
 {
     if (waveOutDevice != null)
     {
         waveOutDevice.Stop();
     }
     if (activeStream != null)
     {
         inputStream.Close();
         inputStream = null;
         ActiveStream.Close();
         ActiveStream = null;
     }
     if (waveOutDevice != null)
     {
         waveOutDevice.Dispose();
         waveOutDevice = null;
     }
 }