示例#1
0
文件: Form1.cs 项目: pclancy/yeti
 private void buttonInFile_Click(object sender, System.EventArgs e)
 {
     if (openFileDialog1.ShowDialog(this) == DialogResult.OK)
     {
         try
         {
             WaveStream s = new WaveStream(openFileDialog1.FileName);
             try
             {
                 m_Config = new Mp3WriterConfig(s.Format);
                 textBoxInFile.Text = openFileDialog1.FileName;
                 textBoxOutFile.Text = System.IO.Path.ChangeExtension(textBoxInFile.Text, ".mp3");
             }
             finally
             {
                 s.Close();
             }
         }
         catch
         {
             MessageBox.Show(this, "Invalid wave file or format", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
             textBoxInFile.Text = "";
             textBoxOutFile.Text = "";
         }
     }
 }
示例#2
0
文件: Form1.cs 项目: pclancy/yeti
 private void buttonCompress_Click(object sender, System.EventArgs e)
 {
     if (File.Exists(textBoxOutFile.Text) && (MessageBox.Show(this, "Override the existing file?", "File exists", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes))
     {
         return;
     }
     try
     {
         progressBar.Value = 0;
         toolTip1.SetToolTip(progressBar, "");
         this.Text = "Audio Compress";
         Compressing = true;
         try
         {
             RefreshControls();
             WaveStream InStr = new WaveStream(textBoxInFile.Text);
             try
             {
                 Mp3Writer writer = new Mp3Writer(new FileStream(textBoxOutFile.Text, FileMode.Create), m_Config);
                 try
                 {
                     byte[] buff = new byte[writer.OptimalBufferSize];
                     int read = 0;
                     int actual = 0;
                     long total = InStr.Length;
                     Cursor.Current = Cursors.WaitCursor;
                     try
                     {
                         while ((read = InStr.Read(buff, 0, buff.Length)) > 0)
                         {
                             Application.DoEvents();
                             writer.Write(buff, 0, read);
                             actual += read;
                             progressBar.Value = (int)(((long)actual * 100) / total);
                             toolTip1.SetToolTip(progressBar, string.Format("{0}% compresssed", progressBar.Value));
                             this.Text = string.Format("Audio Compress - {0}% compresssed", progressBar.Value);
                             Application.DoEvents();
                         }
                         toolTip1.SetToolTip(progressBar, "Done");
                         this.Text = "Audio Compress - Done";
                     }
                     finally
                     {
                         Cursor.Current = Cursors.Default;
                     }
                 }
                 finally
                 {
                     writer.Close();
                 }
             }
             finally
             {
                 InStr.Close();
             }
         }
         finally
         {
             Compressing = false;
             RefreshControls();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(this, ex.Message, "An exception has ocurred with the following message", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }