来自:http://www.cnblogs.com/duanchen/p/4445478.html
1、在Vs2012 工具箱右键-->"选择项"-->"Com组件"-->"Windows Media Player" 勾上,然后点击确定。
2、在WinForm 窗体中添加两个 button按钮,一个Windows Media Player,相应
按钮代码如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
//播放音乐 private void button1_Click( object sender, EventArgs e) { FileDialog open = new OpenFileDialog(); //wxWindowsMediaplayer1是控件名 this .axWindowsMediaPlayer1.settings.playCount = 2; //播放次数; open.Filter = "*.mp3|*.mp3" ; open.Title = "打开文件" ; if (open.ShowDialog() == DialogResult.OK) { axWindowsMediaPlayer1.URL = open.FileName; axWindowsMediaPlayer1.Ctlcontrols.play(); //播放文件 } } //播放视频 private void button2_Click( object sender, EventArgs e) { FileDialog open = new OpenFileDialog(); //wxWindowsMediaplayer1是控件名 this .axWindowsMediaPlayer1.settings.playCount = 2; //播放次数; open.Filter = "*.mp4|*.mp4" ; //文件格式 open.Title = "打开文件" ; if (open.ShowDialog() == DialogResult.OK) { axWindowsMediaPlayer1.URL = open.FileName; axWindowsMediaPlayer1.Ctlcontrols.play(); //播放文件 } } |
效果图:
如果有不对的地方,望园子中的朋友加以指出!