標籤:winform c style class blog code
要做一個視頻無縫切換的程式,所謂無縫就是在一個視頻結束時立即開始另一個視頻,中間不要有切換的黑屏
實現思路是放兩個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; } } }