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
Posted
Comments
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:
http://msdn.microsoft.com/en-us/library/bb383953%28v=vs.90%29.aspx[^]
If you just want to play music, without a media player control, take a look here:
http://msdn.microsoft.com/en-us/library/bb383890%28v=vs.90%29.aspx[^]
   
v2
Comments
Maciej Los 29-Dec-14 12:09pm
   
+5
Thomas Daniels 29-Dec-14 12:09pm
   
Thank you!
ridoy 29-Dec-14 12:37pm
   
5ed!
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.

—SA
   
v3
Comments
Maciej Los 29-Dec-14 12:18pm
   
Good advice ;)
Sergey Alexandrovich Kryukov 29-Dec-14 12:20pm
   
Thank you, Maciej.
—SA
Thomas Daniels 29-Dec-14 12:39pm
   
Good answer, 5'ed.
Sergey Alexandrovich Kryukov 29-Dec-14 12:41pm
   
Thank you.
—SA
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.
—SA
Farhan Bajrai 30-Apr-15 11:48am
   
Agree.
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)?
—SA
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[^]
   
Comments
Thomas Daniels 29-Dec-14 12:44pm
   
+5!
ridoy 29-Dec-14 12:48pm
   
Thank you.
Member 11308295 30-Dec-14 6:31am
   
http://www.c-sharpcorner.com/UploadFile/8ea152/mp3-media-player-in-C-Sharp-4-0/
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