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; } } }
protected void 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; } } }
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; } } }
Convert(string inputFile, string outputFile, soundFormat convertTo, MadlldlibWrapper.Callback updateStatus) { // Handle incorrect output types if (!(convertTo == soundFormat.WAV) && !(convertTo == soundFormat.RAW)) { throw new Exception( "Cannot convert from MP3 to this format directly: " + convertTo); } // Check that file is MP3 // Search through .5 of file // before quitting MP3Check verifyMP3 = new MP3Check(inputFile, 2); if (!verifyMP3.Check()) { throw new Exception("Not a valid MP3 file: " + inputFile); } // Convert to short pathnames inputFilePath.Capacity = MAX_STRLEN; outputFilePath.Capacity = MAX_STRLEN; GetShortPathName(inputFile, inputFilePath, MAX_STRLEN); GetShortPathName(outputFile, outputFilePath, MAX_STRLEN); // Assign if returned path is not zero: if (inputFilePath.Length > 0) { inputFile = inputFilePath.ToString(); } if (outputFilePath.Length > 0) { outputFile = outputFilePath.ToString(); } // status/error message reporting. // String length must be set // explicitly StringBuilder status = new StringBuilder(); status.Capacity = 256; // call the decoding function if (convertTo == soundFormat.WAV) { MadlldlibWrapper.DecodeMP3(inputFile, outputFile, MadlldlibWrapper.DEC_WAV, status, updateStatus); } else // Convert to PCM (raw): { MadlldlibWrapper.DecodeMP3(inputFile, outputFile, MadlldlibWrapper.DEC_PCM, status, updateStatus); } // this prevents garbage collection // from occurring on callback GC.KeepAlive(updateStatus); }
//konvertovanje private void Konvertovanje() { if ((int)outputFileFormat == (int)Aumpel.soundFormat.MP3) { try { Aumpel.Reporter defaultCallback = new Aumpel.Reporter(ReportStatus); FileInfo fi = new FileInfo(roditelj.aktuelnaPjesma); soundFileSize = (int)fi.Length; SaveFileDialog saveFile = new SaveFileDialog(); saveFile.Filter = "MP3 (*.mp3)|*.mp3"; if (saveFile.ShowDialog() == DialogResult.OK) { audioConverter.Convert(roditelj.aktuelnaPjesma, (int)inputFileFormat, saveFile.FileName, (int)outputFileFormat, defaultCallback); SetControlPropertyValue(progressBar1, "value", 0); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); return; } } else if ((int)inputFileFormat == (int)Aumpel.soundFormat.MP3) { try { MadlldlibWrapper.Callback defaultCallback = new MadlldlibWrapper.Callback(ReportStatusMad); FileInfo fi = new FileInfo(roditelj.aktuelnaPjesma); soundFileSize = (int)fi.Length; SaveFileDialog saveFile = new SaveFileDialog(); saveFile.Filter = "WAV (*.wav)|*.wav"; if (saveFile.ShowDialog() == DialogResult.OK) { audioConverter.Convert(roditelj.aktuelnaPjesma, saveFile.FileName, outputFileFormat, defaultCallback); SetControlPropertyValue(progressBar1, "value", 0); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); return; } } }