C# Winform WindowsMediaPlayer控制項

來源:互聯網
上載者:User

標籤: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;                }            }                    }

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.