private void btnConvert_Click(object sender, EventArgs e) { if (newFormat == IntPtr.Zero) { MessageBox.Show("Please, specify destination format for converting"); return; } string fileName = tbFile2.Text + ".wav"; int size = ar.Milliseconds2Bytes(1000); int len = ar.GetLengthInBytes(); AcmConverter ac = new AcmConverter(oldFormat, newFormat, false); FileStream fs = new FileStream(fileName, FileMode.Create); WaveWriter ww = new WaveWriter(fs, AudioCompressionManager.FormatBytes(newFormat)); pbConvert.Maximum = len; int y = 0; while (y < len) { pbConvert.Value = y; byte[] data = ar.ReadDataInBytes(y, size); if (data.Length == 0) { break; } y += data.Length; byte[] newData = ac.Convert(data); ww.WriteData(newData); } ww.Close(); ar.Close(); gbConvert.Enabled = false; btnMakeMp3.Enabled = tbFile2.Text.ToLower().EndsWith(".wav"); OpenContainingFolder(fileName); }
private void Open() { if (ofdAudio.ShowDialog() == DialogResult.OK) { if (ar != null) { ar.Close(); ar = null; } string fileName = ofdAudio.FileName; ar = null; switch (Path.GetExtension(fileName.ToLower())) { case ".vox": ar = GetVoxReader(fileName, 8000); break; case ".avi": ar = new AviReader(File.OpenRead(fileName)); if (!((AviReader)ar).HasAudio) { MessageBox.Show(string.Format("'{0}' file is not contains audio data", fileName)); return; } break; case ".au": case ".snd": ar = new AuReader(File.OpenRead(fileName)); break; case ".wav": ar = new WaveReader(File.OpenRead(fileName)); break; case ".mp3": ar = new Mp3Reader(File.OpenRead(fileName)); break; default: ar = new DsReader(fileName); if (!((DsReader)ar).HasAudio) { ar = null; MessageBox.Show(string.Format("'{0}' file is not contains audio data", fileName)); } break; } Play(); UpdateToolBar(); } }
private void btnOpen_Click(object sender, EventArgs e) { if (ofdAudio.ShowDialog() == DialogResult.OK) { if (arw != null) { arw.Close(); arw = null; } string fileName = ofdAudio.FileName; arw = null; switch (Path.GetExtension(fileName.ToLower())) { case ".avi": arw = new AviReader(File.Open(fileName, FileMode.Open, FileAccess.ReadWrite)); if (!((AviReader)arw).HasAudio) { MessageBox.Show(string.Format("'{0}' file is not contains audio data", fileName)); return; } break; case ".au": case ".snd": arw = new AuReader(File.OpenRead(fileName)); break; case ".wav": arw = new WaveReadWriter(File.Open(fileName, FileMode.Open, FileAccess.ReadWrite)); break; case ".mp3": arw = new Mp3ReadWriter(File.Open(fileName, FileMode.Open, FileAccess.ReadWrite)); break; default: arw = new DsReader(fileName); if (!((DsReader)arw).HasAudio) { arw = null; MessageBox.Show(string.Format("'{0}' file is not contains audio data", fileName)); } break; } btnPlay.Enabled = arw != null; btnSave.Enabled = arw != null; } }