c# and mp3

Hi!
Can c# play a .mp3 file just like he plays .wav





Answer this question

c# and mp3

  • eam0n

    Thomas82 wrote:
    I think you have to reffrence Windows Media Player within your program in order to play .mp3's (as well as .wmv, .asx, and any other files the WMP plays). Below is a excert of a program I wrote that plays music and videos using the WMP:


    private void button1_Click(object sender, EventArgs e)
    {
    OpenFileDialog openFileDialog1 = new OpenFileDialog();
    openFileDialog1.Filter = "Video (.wmv)|*.wmv|Music (.mp3)|*.mp3|ALL Files (*.*)|*.*";
    openFileDialog1.FilterIndex = 2;
    openFileDialog1.ShowDialog(); //Open File dialog box
    userFile = openFileDialog1.FileName; //userFile = file user chose
    axWindowsMediaPlayer1.URL = userFile; //WMP plays file user chose
    }


    This portion of the program allows the user to open a file that has either a .mp3, .wmv, or any extension and play it in a Windows Media Player like window within the parent form.


    I used this code, as it looks straight forward, but i was told the userFile does not exist in current context. I dont understand why, as i believe it is defined here : userFile = openFileDialog1.FileName; //userFile = file user chose

    any reason aas to why its tellin me this

  • Marian Pascalau

    Another solution is to download WMP SDK:
    http://msdn.microsoft.com/windowsmedia/downloads/default.aspx

    Then you can play mp3 inside of your app on this way:
    (First you need to add Interop.WMPLib.dll refernce)

    WMPLib.WindowsMediaPlayer winmp = new WMPLib.WindowsMediaPlayer();
    wmp.URL = "song_path";
    wmp.controls.play();


  • Enggtp

    how to set the proxy setting manually including IP,PORT,USERNAME and Password.
    i have seen the network property but that doesnt have these properties.

    thanks

    Asim


  • The Aqua

    I think you have to reffrence Windows Media Player within your program in order to play .mp3's (as well as .wmv, .asx, and any other files the WMP plays). Below is a excert of a program I wrote that plays music and videos using the WMP:


    private void button1_Click(object sender, EventArgs e)
    {
    OpenFileDialog openFileDialog1 = new OpenFileDialog();
    openFileDialog1.Filter = "Video (.wmv)|*.wmv|Music (.mp3)|*.mp3|ALL Files (*.*)|*.*";
    openFileDialog1.FilterIndex = 2;
    openFileDialog1.ShowDialog(); //Open File dialog box
    userFile = openFileDialog1.FileName; //userFile = file user chose
    axWindowsMediaPlayer1.URL = userFile; //WMP plays file user chose
    }


    This portion of the program allows the user to open a file that has either a .mp3, .wmv, or any extension and play it in a Windows Media Player like window within the parent form.

  • c# and mp3