user1139666 user1139666 - 2 months ago 13
C# Question

Playing a MP3 file in a WinForm application

I am developing a

application. I want to play a MP3 file when the user clicks a button.

The MP3 file is located in the file system of the computer where the application is executed.

I have Googled for a while and I have found information about the
class. But I have read that the
class can only be used to play files in .wav format.

What classes can be used to play files in .mp3 format ?

Any help will be greatly appreciated.

Max Max

The link below, gives a very good tutorial, about playing mp3 files from a windows form with c#:

This link will lead you to a topic, which contains a lot information about how to play an mp3 song, using Windows forms. It also contains a lot of other projects, trying to achieve the same thing:

For example use this code for .mp3:

WMPLib.WindowsMediaPlayer wplayer = new WMPLib.WindowsMediaPlayer();

wplayer.URL = "My MP3 file.mp3";

Then only put the wplayer.Controls.Play(); in the Button_Click event.

For example use this code for .wav:

System.Media.SoundPlayer player = new System.Media.SoundPlayer();

player.SoundLocation = "Sound.wav";

Put the player.Play(); in the Button_Click event, and it will work.