1. On the VS2012 Toolbox right---"select"-"COM Components" and "Windows Media Player" Tick on, then click OK.
2. In the WinForm form, add two button buttons, one Windows Media Player, and the corresponding
The button code is as follows:
Play Music private void button1_click (object sender, EventArgs e) {FileDialog open = new OpenFileDialog (); WxWindowsMediaplayer1 is the control name This.axWindowsMediaPlayer1.settings.playCount = 2;//played; ope N.filter = "*.mp3|*.mp3"; Open. Title = "Open File"; if (open. ShowDialog () = = DialogResult.OK) {axwindowsmediaplayer1.url = open. FileName; AxWindowsMediaPlayer1.Ctlcontrols.play ();//Play File}}//play video private void Button2_Click (object sender, Eve Ntargs e) {FileDialog open = new OpenFileDialog (); WxWindowsMediaplayer1 is the control name This.axWindowsMediaPlayer1.settings.playCount = 2;//played; open. Filter = "*.mp4|*.mp4"; File format Open. Title = "Open File"; if (open. ShowDialog () = = DialogResult.OK) {axwindowsmediaplayer1.url = open. FileName; AxWindowsMediaPlayer1.Ctlcontrols.play ();Play file}}
:
If there is a wrong place, look at the garden friends to point out!
Play MP3, MP4 files in WinForm