Play a mp3 sound using MediaPlayer in C#.

Here is sample coding for how to play a mp3 song in C# applicatin using AxWMPLib library.

- First add the library from Com reference with the name of Windows Media Player (wmp.dll).

- Drag the media player control from tool box in to your form.

- Copy the following code into Form_Load


axWindowsMediaPlayer1.URL = "C:\\test.mp3";
axWindowsMediaPlayer1.Ctlcontrols.stop();


- Copy the following code when click the play button


axWindowsMediaPlayer1.Ctlcontrols.play();

- Copy the following code when click the pause button.


axWindowsMediaPlayer1.Ctlcontrols.pause();

- We can get the time duration of playing file as follows,


axWindowsMediaPlayer1.currentMedia.attributeCount.ToString();

axWindowsMediaPlayer1.currentMedia.durationString;

axWindowsMediaPlayer1.Ctlcontrols.currentPositionString;


...S.VinothkumaR.

7 comments:

oasisfleeting said...

Great!! Exactly what i was looking for. :)

Wilman Arambillete said...

Great this is exactly what I needed
There's one little detail, once you add the reference you must explicitly add the new component to the toolbox.
Thanks a lot for your help

Wilman Arambillete said...
This comment has been removed by the author.
Wilman Arambillete said...
This comment has been removed by the author.
Unknown said...
This comment has been removed by the author.
kadek surya pranata said...

thanks vinothkumar.. you help me creating my timer... ;-)

Prakash Porua said...

hi ...
how can i give multiple URL's to axwindowsmediaplayer .
i want to create a windows form which contains buttons and when the user clicks on a button the particular mp3 urL present in that button should be playe in the media player .