Click here to Skip to main content
14,244,354 members
Rate this:
Please Sign up or sign in to vote.
See more:
hello how can i use media player in a winform? i want the user of my app to be able to listen to music while using the app.
is there any code in the codeproject that can help.
or any help
thank you
BillWoodruff 29-Dec-14 12:07pm
Please search CodeProject for "media player," "play music," "DirectSound," etc.

There are many resources here.
Rate this:
Please Sign up or sign in to vote.

Solution 1

Have a look at this MSDN article about adding a media player:[^]
If you just want to play music, without a media player control, take a look here:[^]
Maciej Los 29-Dec-14 12:09pm
Thomas Daniels 29-Dec-14 12:09pm
Thank you!
ridoy 29-Dec-14 12:37pm
Thomas Daniels 29-Dec-14 12:39pm
Thank you!
Member 11308295 29-Dec-14 12:40pm
thank u a lot. but what about if I wanna play an mp3 song?
Member 11308295 29-Dec-14 12:54pm
it didn't work :( I think something is missing in the code.
have you tried it before?
Thomas Daniels 29-Dec-14 12:55pm
You first have to import the Windows Media Player library.

If you use Visual Studio, go to "References", and switch to the "COM" tab. In that tab, look for WMPLib or Windows Media Player, and add it. Then it should work.
Member 11308295 29-Dec-14 13:01pm
I did all of these steps and still not working. No sound, no choice of a song, no enable play button!!
Thomas Daniels 29-Dec-14 13:04pm
Note that the MP3 player does not show a control on your form. Only the first link provides a control. You can try providing an MP3 file there.
Rate this:
Please Sign up or sign in to vote.

Solution 2

In addition to the Solution 1:

What you want make sense only if you want to play some audio related to your application. Say, for applications related to music, you can play what the user edits (or something like that); in other cases, it could be instructional audio.

If your music is unrelated to the task, adding music would be purely negative quality. Why? Because all system capable of playing do have a separate player, and because your user knows better than you what to play and when. Adding such feature to the application means pushing the user to do something you think should be done, not the user. It could be so irritating (even if it is optional) that the user may decide to avoid using your products. Seriously.

Maciej Los 29-Dec-14 12:18pm
Good advice ;)
Sergey Alexandrovich Kryukov 29-Dec-14 12:20pm
Thank you, Maciej.
Thomas Daniels 29-Dec-14 12:39pm
Good answer, 5'ed.
Sergey Alexandrovich Kryukov 29-Dec-14 12:41pm
Thank you.
Prince Tegaton 29-Dec-14 12:40pm
I totally agree with Sergey Alexandrovich.
Playing music with your app has deviated from the main goal.
It will also consume more resources talking about memory needed to run the application. Instead, if you want the user to enjoy music when using the app you can launch the windows media player from code with Process.Start("wmplayer") or you send the selected audio file to the player.
Sergey Alexandrovich Kryukov 29-Dec-14 12:43pm
Thank you, but my idea is: even starting wmplayer would be the negative quality. First, this player may not even be installed. Importantly, the user knows better what application to start and when.
Farhan Bajrai 30-Apr-15 11:48am
Member 11308295 29-Dec-14 12:55pm
thank you for the advice
Sergey Alexandrovich Kryukov 29-Dec-14 12:59pm
You are welcome. Will you accept this and/or other answers formally (green "Accept" button)?
Rate this:
Please Sign up or sign in to vote.

Solution 4

ProgramFOX already provided what you need, just some more extension for you:
Audio and Video Player C# Winform[^]
Playing a MP3 file in a WinForm application[^]
Audio and Video Player C# Winform[^]
Thomas Daniels 29-Dec-14 12:44pm
ridoy 29-Dec-14 12:48pm
Thank you.
Member 11308295 30-Dec-14 6:31am
this link is helpful for mp3 song playing.:D

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100