Below is my code in Form1.cs page.In the below code near
public static void Main( )
{
Application.Run(new TestForm( ));
}
in the last and near the constructor
public TestForm()
{
i am getting error as method must have return type while compling and the code in my
program.cs is
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DssToWav
{
static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
Form1.cs
<pre lang="C#">using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System;
using System.IO;
using Arbingersys.Audio.Aumplib;
namespace DssToWav
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private string inputFile = "Not set";
private string outputFile = "Not set";
private Label label1;
private ComboBox comboBox1;
private Label comboBox1Label;
private Button convertButton;
private static ProgressBar progressBar1;
private Button sourceFileButton;
private Label sourceFileLabel;
private Button destFileButton;
private Label destFileLabel;
string[] convertFormat = new string[] {"WAV", "MP3", "AU", "AIFF"};
private Aumpel audioConverter = new Aumpel();
private Aumpel.soundFormat inputFileFormat;
private Aumpel.soundFormat outputFileFormat;
public TestForm()
{
this.label1 = new Label();
this.convertButton = new Button();
progressBar1 = new ProgressBar();
this.sourceFileButton = new Button();
this.sourceFileLabel = new Label();
this.destFileButton = new Button();
this.destFileLabel = new Label();
this.comboBox1 = new ComboBox();
this.comboBox1Label = new Label();
this.Text = "TestForm";
label1.Location = new System.Drawing.Point (10, 10);
label1.Text = "Select a file to convert and a destination.";
label1.Size = new System.Drawing.Size (216, 16);
convertButton.Location = new System.Drawing.Point (300,80);
convertButton.Size = new System.Drawing.Size (65, 22);
convertButton.Text = "&Convert";
sourceFileButton.Location = new System.Drawing.Point (10,30);
sourceFileButton.Size = new System.Drawing.Size (100, 22);
sourceFileButton.Text = "&File to convert:";
sourceFileLabel.Location = new System.Drawing.Point (10, 55);
sourceFileLabel.Size = new System.Drawing.Size (375, 22);
sourceFileLabel.Text = inputFile;
destFileButton.Location = new System.Drawing.Point (10,80);
destFileButton.Size = new System.Drawing.Size (100, 22);
destFileButton.Text = "&Save to:";
destFileLabel.Location = new System.Drawing.Point (10, 105);
destFileLabel.Size = new System.Drawing.Size (375, 22);
destFileLabel.Text = outputFile;
comboBox1Label.Location = new System.Drawing.Point (120,80);
comboBox1Label.Size = new System.Drawing.Size(90,16);
comboBox1Label.Text = "Convert to:";
comboBox1.Location = new System.Drawing.Point (216,80);
comboBox1.Size = new System.Drawing.Size(75,10);
this.comboBox1.Items.AddRange(convertFormat);
progressBar1.Location = new System.Drawing.Point(10, 145);
progressBar1.Size = new System.Drawing.Size(375, 22);
progressBar1.Minimum = 0;
progressBar1.Maximum = 100;
sourceFileButton.Click +=
new System.EventHandler (this.sourceFileButton_Click);
destFileButton.Click +=
new System.EventHandler (this.destFileButton_Click);
convertButton.Click +=
new System.EventHandler (this.convertButton_Click);
this.AutoScaleBaseSize = new System.Drawing.Size (5, 13);
this.ClientSize = new System.Drawing.Size (400, 200);
this.Controls.Add (this.convertButton);
this.Controls.Add (this.sourceFileButton);
this.Controls.Add (this.sourceFileLabel);
this.Controls.Add (this.destFileButton);
this.Controls.Add (this.destFileLabel);
this.Controls.Add (this.label1);
this.Controls.Add (this.comboBox1);
this.Controls.Add (this.comboBox1Label);
this.Controls.Add (progressBar1);
}
public static int soundFileSize = 0;
private static void
ReportStatus(int totalBytes,
int processedBytes, Aumpel aumpelObj)
{
progressBar1.Value =
(int)(((float)processedBytes/(float)totalBytes)*100);
}
private static bool
ReportStatusMad(uint frameCount, uint byteCount,
ref MadlldlibWrapper.mad_header mh)
{
progressBar1.Value =
(int)(((float)byteCount/(float)soundFileSize)*100);
return true;
}
private void
ShowExceptionMsg(Exception e)
{
MessageBox.Show("Exception: " + e.Message,
"Exception!", MessageBoxButtons.OK);
}
protected void
sourceFileButton_Click (object sender, System.EventArgs e)
{
OpenFileDialog openFile = new OpenFileDialog();
openFile.Filter = "MP3 (*.mp3)|*.mp3|WAV (*.wav)|" +
"*.wav|All Files (*.*)|*.*";
openFile.FileName = "" ;
openFile.CheckFileExists = true;
openFile.CheckPathExists = true;
if ( openFile.ShowDialog() != DialogResult.OK )
return;
try
{
inputFileFormat =
audioConverter.CheckSoundFormat(openFile.FileName);
}
catch(Exception ex)
{
ShowExceptionMsg(ex);
return;
}
sourceFileLabel.Text = inputFile = openFile.FileName;
}
protected void
destFileButton_Click (object sender, System.EventArgs e)
{
SaveFileDialog saveFile = new SaveFileDialog();
saveFile.Filter = "MP3 (*.mp3)|*.mp3|" +
"WAV (*.wav)|*.wav|" +
"AIFF (*.aiff)|*.aiff|" +
"AU (*.au)|*.au|" +
"All Files (*.*)|*.*";
if ( saveFile.ShowDialog() != DialogResult.OK )
return;
destFileLabel.Text = outputFile = saveFile.FileName;
}
protected void
convertButton_Click (object sender, System.EventArgs e)
{
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;
}
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;
}
}
else if ( (int)inputFileFormat == (int)Aumpel.soundFormat.MP3 )
{
try
{
MadlldlibWrapper.Callback defaultCallback =
new MadlldlibWrapper.Callback(ReportStatusMad);
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;
}
}
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;
}
}
}
public static void Main( )
{
Application.Run(new TestForm( ));
}
}
}
What I have tried:
Can anybody help me out how to handle this