Try this:
foreach( var item in listBox1.Items )
{
string mp3File = folderBrowserDialog2.SelectedPath + "\\" + item + ".mp3";
string outputFile = folderBrowserDialog1.SelectedPath + "\\" + item + ".wav";
. . .
}
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello... i have this code but my loop is not working...i want to apply the code to all items in the listbox...but i cannot perform the loop...it keeps applying the code just to 1 file... any help? Thanks!
for (int i = 0; i < 100; i++)
{
string mp3File = folderBrowserDialog2.SelectedPath + "\\" + listBox1.SelectedItem + ".mp3";
string outputFile = folderBrowserDialog1.SelectedPath + "\\" + listBox1.SelectedItem + ".wav";
int samples = Int32.Parse(comborate.Text);
int bits = Int32.Parse(combobits.Text);
int channs = Int32.Parse(combochans.Text);
using (Mp3FileReader reader = new Mp3FileReader(mp3File))
{
progressBar1.Value = 0;
using (WaveStream pcmStream = new WaveFormatConversionStream(new WaveFormat(samples, bits, channs), reader))
{
WaveFileWriter.CreateWaveFile(outputFile, pcmStream);
}
progressBar1.PerformStep();
}
Try this:
foreach( var item in listBox1.Items )
{
string mp3File = folderBrowserDialog2.SelectedPath + "\\" + item + ".mp3";
string outputFile = folderBrowserDialog1.SelectedPath + "\\" + item + ".wav";
. . .
}
Hi,@Duarte Vinagre. Welcome Microsoft Q&A. You could also update the code as follows.
private void button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < listBox1.Items.Count; i++)
{
string mp3File = folderBrowserDialog2.SelectedPath + "\\" + listBox1.Items[i] + ".mp3";
string outputFile = folderBrowserDialog1.SelectedPath + "\\" + listBox1.Items[i] + ".wav";
int samples = Int32.Parse(comborate.Text);
int bits = Int32.Parse(combobits.Text);
int channs = Int32.Parse(combochans.Text);
using (Mp3FileReader reader = new Mp3FileReader(mp3File))
{
progressBar1.Value = 0;
using (WaveStream pcmStream = new WaveFormatConversionStream(new WaveFormat(samples, bits, channs), reader))
{
WaveFileWriter.CreateWaveFile(outputFile, pcmStream);
}
progressBar1.PerformStep();
}
}
}
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.