Dispose() protected method

Dispose of object
protected Dispose ( bool final ) : void
final bool True if called from destructor, false otherwise
return void
示例#1
3
 public static void ConvertWavToMp3(string WavFile, string outPutFile)
 {
     CheckAddBinPath();
     WaveFileReader rdr = new WaveFileReader(WavFile);
     using (var wtr = new LameMP3FileWriter(outPutFile, rdr.WaveFormat, 128))
     {
         rdr.CopyTo(wtr);
         rdr.Dispose();
         wtr.Dispose();
         return;
     }
 }
示例#2
0
        public MemoryStream GetMp3Sample(int seconds, string filepath = "")
        {
            try
            {
                var stream = new MemoryStream();
                // Start recording from loopback
                IWaveIn waveIn = new WasapiLoopbackCapture();
                waveIn.DataAvailable += waveIn_DataAvailable;
                waveIn.RecordingStopped += waveIn_RecordingStopped;
                // Setup MP3 writer to output at 96kbit/sec
                writer = new LameMP3FileWriter(stream, waveIn.WaveFormat, LAMEPreset.ABR_96);
                _isRecording = true;
                waveIn.StartRecording();

                // Wait for X seconds
                System.Threading.Thread.Sleep(seconds * 1000);
                waveIn.StopRecording();

                // flush output to finish MP3 file correctly
                writer.Flush();
                // Dispose of objects
                waveIn.Dispose();
                writer.Dispose();

                if (filepath != "")
                    using (var file = new FileStream(filepath, FileMode.Create, FileAccess.Write))
                        stream.WriteTo(file);

                return stream;
            }
            catch (Exception)
            {
                throw;
            }
        }
        private void StopRecord(Exception e)
        {
            lock (_lck) {
                _ripper.FrameDecompressed -= OnFrameDecompressed;
                _ripper.StreamEnded       -= (ex) => StopRecord(ex);

                if (_mp3writer != null)
                {
                    _mp3writer.Dispose();
                    _mp3writer = null;
                }

                if (_fileStream != null)
                {
                    _fileStream.Dispose();
                    _fileStream = null;
                }

                State = StreamRecorderStates.Stopped;

                if (_recordingEnded != null)
                {
                    _recordingEnded(e);
                }
            }
        }
示例#4
0
        public void ConvertWavToMp3(string WavFile, string outPutFile)
        {
            WaveFileReader rdr = new WaveFileReader(WavFile);

            using (var wtr = new NAudio.Lame.LameMP3FileWriter(outPutFile, rdr.WaveFormat, 128))
            {
                rdr.CopyTo(wtr);
                rdr.Dispose();
                wtr.Dispose();
                return;
            }
        }