1,、在所有windows窗體中添加windows media player控件
2,、拖入windows media player控件,編寫(xiě)代碼
using System.Collections.Generic; using System.ComponentModel; using System.Windows.Forms; using DevExpress.XtraEditors; namespace DXProject.Core.page public partial class YrForm : DevExpress.XtraEditors.XtraForm public YrForm(string path) SetStyle(ControlStyles.UserPaint, true); SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景. SetStyle(ControlStyles.DoubleBuffer, true); // 雙緩沖 //FileDialog open = new OpenFileDialog(); //wxWindowsMediaplayer1是控件名 this.axWindowsMediaPlayer1.settings.playCount = 1;//播放次數(shù),; //open.Filter = "*.mp4|*.mp4"; //文件格式 //open.Title = "打開(kāi)文件"; //if (open.ShowDialog() == DialogResult.OK) axWindowsMediaPlayer1.URL = path; axWindowsMediaPlayer1.Ctlcontrols.play();//播放文件 axWindowsMediaPlayer1.StatusChange += windowsMediaPlay_StatusChange; protected override void WndProc(ref Message m) if (m.Msg == 0x0014) // 禁掉清除背景消息 protected override CreateParams CreateParams CreateParams cp = base.CreateParams; cp.ExStyle |= 0x02000000; void windowsMediaPlay_StatusChange(object sender, EventArgs e) * 0 Undefined Windows Media Player is in an undefined state.(未定義) 1 Stopped Playback of the current media item is stopped.(停止) 2 Paused Playback of the current media item is paused. When a media item is paused, resuming playback begins from the same location.(停留) 3 Playing The current media item is playing.(播放) 4 ScanForward The current media item is fast forwarding. 5 ScanReverse The current media item is fast rewinding. 6 Buffering The current media item is getting additional data from the server.(轉(zhuǎn)換) 7 Waiting Connection is established, but the server is not sending data. Waiting for session to begin.(暫停) 8 MediaEnded Media item has completed playback. (播放結(jié)束) 9 Transitioning Preparing new media item. 10 Ready Ready to begin playing.(準(zhǔn)備就緒) 11 Reconnecting Reconnecting to stream.(重新連接) if ((int)axWindowsMediaPlayer1.playState == 1) System.Threading.Thread.Sleep(100); //axWindowsMediaPlayer1.Ctlcontrols.play(); else if ((int)axWindowsMediaPlayer1.playState == 3) //axWindowsMediaPlayer1.fullScreen = true; // this.axWindowsMediaPlayer1.Ctlcontrols.stop(); private void YrForm_Load(object sender, EventArgs e) private void YrForm_FormClosing(object sender, FormClosingEventArgs e) //this.axWindowsMediaPlayer1.Ctlcontrols.stop(); private void simpleButton1_Click(object sender, EventArgs e) axWindowsMediaPlayer1.fullScreen = true;
|