Monday, November 22, 2010

C# Tutorial: Create a Simple MP3 Player

Here is the code

string[] files, paths;
///////////////////////////////////////
private void button1_Click(object sender, EventArgs e)
{
    if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
    {
        files = openFileDialog1.SafeFileNames; // Save only the names
        paths = openFileDialog1.FileNames; // Save the full paths
        for (int i = 0; i < files.Length; i++)
        {
            listBox1.Items.Add(files[i]); // Add songs to the listbox
        }
    }
}
//////////////////////////////////////////
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
    axWindowsMediaPlayer1.URL = paths[listBox1.SelectedIndex]; // Play the song  
}

Or download the solution

6 comments:

  1. dc nu merg butoanele de next si previous ? cum as putea sa le activez? si e un bug: daca bag 2-3 melodii si apoi mai adaug inca una mi se blocheaza trebuie sa bag mai multe ca sa mearga. Trebuie optimizat listboxul. E-mail me pls:D

    ReplyDelete
  2. But what if I wan't it to auto play all the songs I have selected??

    ReplyDelete
  3. But what if I wan't it to auto play all the songs I have selected??

    ReplyDelete