Beispiel #1
0
        convertButton_Click(object sender, System.EventArgs e)
        {
            // Set conversion type

            switch ((string)comboBox1.SelectedItem)
            {
            case "WAV":
                outputFileFormat = Aumpel.soundFormat.WAV;
                break;

            case "MP3":
                outputFileFormat = Aumpel.soundFormat.MP3;
                break;

            case "AU":
                outputFileFormat = Aumpel.soundFormat.AU;
                break;

            case "AIFF":
                outputFileFormat = Aumpel.soundFormat.AIFF;
                break;

            default:
                MessageBox.Show("You must select a type to convert to.",
                                "Error", MessageBoxButtons.OK);
                return;
            }


            // Convert to MP3

            if ((int)outputFileFormat == (int)Aumpel.soundFormat.MP3)
            {
                try
                {
                    Aumpel.Reporter defaultCallback =
                        new Aumpel.Reporter(ReportStatus);

                    audioConverter.Convert(inputFile,
                                           (int)inputFileFormat, outputFile,
                                           (int)outputFileFormat, defaultCallback);

                    progressBar1.Value = 0;

                    destFileLabel.Text   = outputFile = "";
                    sourceFileLabel.Text = inputFile = "";

                    MessageBox.Show("Conversion finished.",
                                    "Done.", MessageBoxButtons.OK);
                }
                catch (Exception ex)
                {
                    ShowExceptionMsg(ex);
                    return;
                }
            }

            // From MP3 (using named pipe):

            else if ((int)inputFileFormat == (int)Aumpel.soundFormat.MP3)
            {
                try
                {
                    MadlldlibWrapper.Callback defaultCallback =
                        new MadlldlibWrapper.Callback(ReportStatusMad);

                    // Determine file size
                    FileInfo fi = new FileInfo(inputFile);
                    soundFileSize = (int)fi.Length;

                    audioConverter.Convert(inputFile,
                                           outputFile, outputFileFormat, defaultCallback);
                    progressBar1.Value = 0;

                    destFileLabel.Text   = outputFile = "";
                    sourceFileLabel.Text = inputFile = "";

                    MessageBox.Show("Conversion finished.",
                                    "Done.", MessageBoxButtons.OK);
                }
                catch (Exception ex)
                {
                    ShowExceptionMsg(ex);
                    return;
                }
            }

            // Non-MP3 soundfile conversion:

            else
            {
                try
                {
                    Aumpel.Reporter defaultCallback =
                        new Aumpel.Reporter(ReportStatus);

                    audioConverter.Convert(inputFile,
                                           (int)inputFileFormat,
                                           outputFile,
                                           (int)(outputFileFormat | Aumpel.soundFormat.PCM_16),
                                           defaultCallback);

                    progressBar1.Value = 0;

                    destFileLabel.Text   = outputFile = "";
                    sourceFileLabel.Text = inputFile = "";

                    MessageBox.Show("Conversion finished.",
                                    "Done.", MessageBoxButtons.OK);
                }
                catch (Exception ex)
                {
                    ShowExceptionMsg(ex);
                    return;
                }
            }
        }
Beispiel #2
0
        private void convertButton_Click(object sender, EventArgs e)
        {
            // 设置转换格式
            switch (formatBox.SelectedItem.ToString())
            {
            case "WAV":
                outputFileFormat = Aumpel.soundFormat.WAV;
                break;

            case "MP3":
                outputFileFormat = Aumpel.soundFormat.MP3;
                break;

            case "AU":
                outputFileFormat = Aumpel.soundFormat.AU;
                break;

            case "AIFF":
                outputFileFormat = Aumpel.soundFormat.AIFF;
                break;

            default:
                MessageBox.Show("You must select a valid type to convert to.",
                                "Error",
                                MessageBoxButtons.OK);
                return;
            }

            // 转换为MP3(Aumpel库)
            if ((int)outputFileFormat == (int)Aumpel.soundFormat.MP3)
            {
                try
                {
                    Aumpel.Reporter defaultCallback = new Aumpel.Reporter(ReportStatus);

                    audioConverter.Convert(inputFile, (int)inputFileFormat,
                                           outputFile, (int)outputFileFormat,
                                           defaultCallback);

                    convertProgressBar.Value = 0;

                    destFileLabel.Text   = outputFile = "";
                    sourceFileLabel.Text = inputFile = "";

                    MessageBox.Show("Conversion finished.",
                                    "Done",
                                    MessageBoxButtons.OK);
                }
                catch (Exception ex)
                {
                    ShowExceptionMsg(ex);
                    return;
                }
            }

            // MP3转换为其他(Madlldlib库)
            else if ((int)inputFileFormat == (int)Aumpel.soundFormat.MP3)
            {
                try
                {
                    MadlldlibWrapper.Callback defaultCallback =
                        new MadlldlibWrapper.Callback(ReportStatusMad);

                    // 确定文件大小
                    FileInfo f = new FileInfo(inputFile);
                    soundFileSize = (int)f.Length;

                    audioConverter.Convert(inputFile,
                                           outputFile,
                                           outputFileFormat,
                                           defaultCallback);
                    convertProgressBar.Value = 0;

                    destFileLabel.Text   = outputFile = "";
                    sourceFileLabel.Text = inputFile = "";

                    MessageBox.Show("Conversion finifshed.",
                                    "Done.", MessageBoxButtons.OK);
                }
                catch (Exception ex)
                {
                    ShowExceptionMsg(ex);
                    return;
                }
            }

            // 源文件非MP3的转换
            else
            {
                try
                {
                    Aumpel.Reporter defaultCallback =
                        new Aumpel.Reporter(ReportStatus);

                    audioConverter.Convert(inputFile, (int)inputFileFormat,
                                           outputFile, (int)(outputFileFormat | Aumpel.soundFormat.PCM_16),
                                           defaultCallback);

                    convertProgressBar.Value = 0;

                    destFileLabel.Text   = outputFile = "";
                    sourceFileLabel.Text = inputFile = "";

                    MessageBox.Show("Conversion finished.",
                                    "Done.",
                                    MessageBoxButtons.OK);
                }
                catch (Exception ex)
                {
                    ShowExceptionMsg(ex);
                    return;
                }
            }
        }