public partial class VedioForm : Form
{
public VedioForm()
{
InitializeComponent();
}
private void VedioForm_Load(object sender, EventArgs e)
{
timer1.Enabled = true;//开启视频进度查询时钟(500ms)
axWindowsMediaPlayer1.URL = @"D:\Debug\background.mp4";//查找添加指定路径的mp4地址
}
private void VedioForm_FormClosed(object sender, FormClosedEventArgs e)
{
System.Environment.Exit(0);
}
private void axWindowsMediaPlayer1_StatusChange(object sender, EventArgs e)
{
// 判断视频是否已停止播放播放状态,1 = 停止,2 = 暂停,3 = 播放,6 = 正在缓冲,9 = 正在连接,10 = 准备就绪
if (axWindowsMediaPlayer1.playState == WMPLib.WMPPlayState.wmppsPaused)
{
//设定不允许暂停
axWindowsMediaPlayer1.Ctlcontrols.play();
}
}
//添加一个timer1控件检查播放进度//防止播放中的视频结束,出现黑屏界面。
private void timer1_Tick(object sender, EventArgs e)
{
int vediotime = (int)axWindowsMediaPlayer1.currentMedia.duration - 1;//正在播放的视频总进度-1
int playtime = (int)axWindowsMediaPlayer1.Ctlcontrols.currentPosition;//正在播放的视频总进度
if (playtime == vediotime)
{
axWindowsMediaPlayer1.Ctlcontrols.currentPosition = 0;//跳转到开头
}
}
}