码迷,mamicode.com
首页 > Windows程序 > 详细

C# Winform WindowsMediaPlayer控件

时间:2014-05-31 21:18:04      阅读:555      评论:0      收藏:0      [点我收藏+]

标签:winform   c   style   class   blog   code   

要做一个视频无缝切换的程序,所谓无缝就是在一个视频结束时立即开始另一个视频,中间不要有切换的黑屏

实现思路是放两个wmp播放控件,其中每个时刻只有一个在播放,另外一个处于暂停状态,并隐藏

当一个视频播放完后,切换显示另一个视频,同时这个视频隐藏起来并加载下一段视频,视频加载完成后(wmp会有事件通知)暂停

这样就去除了加载时的短暂空挡

有时可能会有键盘鼠标事件影响wmp的状态,所以使用定时器虽然监测wmp的播放状态

bubuko.com,布布扣
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;
            
        }
bubuko.com,布布扣
bubuko.com,布布扣
 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;
                }
            }            
        }
bubuko.com,布布扣

 

C# Winform WindowsMediaPlayer控件,布布扣,bubuko.com

C# Winform WindowsMediaPlayer控件

标签:winform   c   style   class   blog   code   

原文地址:http://www.cnblogs.com/erictanghu/p/3760956.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!