C# Winform WindowsMediaPlayer控件
时间:2014-05-31 21:18:04
收藏:0
阅读:555
要做一个视频无缝切换的程序,所谓无缝就是在一个视频结束时立即开始另一个视频,中间不要有切换的黑屏
实现思路是放两个wmp播放控件,其中每个时刻只有一个在播放,另外一个处于暂停状态,并隐藏
当一个视频播放完后,切换显示另一个视频,同时这个视频隐藏起来并加载下一段视频,视频加载完成后(wmp会有事件通知)暂停
这样就去除了加载时的短暂空挡
有时可能会有键盘鼠标事件影响wmp的状态,所以使用定时器虽然监测wmp的播放状态
private void Form1_Load(object sender, EventArgs e) { timer1.Enabled = true; wmp1.URL = ConfigurationManager.AppSettings["File1Path"]; wmp2.URL = ConfigurationManager.AppSettings["File1Path"]; playnow = 1; wmpnow = 1; wmp1.Visible = true; wmp2.Visible = false; wmp1pause = 0; wmp2pause = 0; }
private bool isFullScreen = false; private int playnow = 1; private int wmp1pause = 0; private int wmp2pause = 0; private int wmpnow = 1; private void timer1_Tick(object sender, EventArgs e) { if (wmp1.Ctlcontrols.currentPosition == 0) wmp1.Ctlcontrols.play(); else { if (wmp1.Ctlcontrols.currentPosition > 0 && wmp1pause==0 && wmpnow==2) { if (playnow == 2) { wmp1.Visible = true; wmp1.settings.volume = wmp2.settings.volume; wmpnow = 1; playnow = 1; wmp2.Visible = false; wmp2.Ctlcontrols.stop(); wmp2pause = 0; } else wmp1.Ctlcontrols.pause(); wmp1pause = 1; } if (wmp1.currentMedia.duration - wmp1.Ctlcontrols.currentPosition < 0.05) { wmpnow = 2; wmp2.Visible = true; wmp2.settings.volume = wmp1.settings.volume; wmp2.Ctlcontrols.play(); wmp1.Visible = false; wmp1.Ctlcontrols.stop(); wmp1.URL = ConfigurationManager.AppSettings["File1Path"]; wmp1pause = 0; } } if (wmp2.Ctlcontrols.currentPosition == 0) wmp2.Ctlcontrols.play(); else { if (wmp2.Ctlcontrols.currentPosition > 0 && wmp2pause == 0 && wmpnow==1) { if (playnow == 2) { wmp2.Visible = true; wmp2.settings.volume = wmp1.settings.volume; wmpnow = 2; playnow = 1; wmp1.Visible = false; wmp1.Ctlcontrols.stop(); wmp1pause = 0; } else wmp2.Ctlcontrols.pause(); wmp2pause = 1; } if (wmp2.currentMedia.duration - wmp2.Ctlcontrols.currentPosition < 0.05) { wmpnow = 1; wmp1.Visible = true; wmp1.settings.volume = wmp2.settings.volume; wmp1.Ctlcontrols.play(); wmp2.Visible = false; wmp2.Ctlcontrols.stop(); wmp2.URL = ConfigurationManager.AppSettings["File1Path"]; wmp2pause = 0; } } }
评论(0)