How to play a .mp3 file during the button click event in windows form?
I'm new to C# and any pointers to this will be really helpful.
You can use WindowsMediaPlayer COM control to play mp3.
Here is a guide from msdn.
WMPLib.WindowsMediaPlayer player = new WMPLib.WindowsMediaPlayer();
player.URL = @"track.mp3";
player.controls.play();
Also you can use SoundPlayer to play wav files. There are also several third party .net mp3 libraries.
I wonder if you can 'steal' WPF's MediaPlayer which is like the mentioned SoundPlayer, but also capable of playing MP3.
var player = new System.Windows.Media.MediaPlayer();
player.Open(new System.Uri("myfile.mp3"));
player.Play();
Haven't tried it, but it could work and this way you don't need to use an external library. More info on MSDN: http://msdn.microsoft.com/en-us/library/system.windows.media.mediaplayer
you must use .wav sound files , tht's the easiest and best way to play a sound clip
System.Media.SoundPlayer s = new System.Media.SoundPlayer();
s.SoundLocation = "C:\\mps.wav" ;
s.Load() ;
s.Play();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With