关联WMP播放状态事件(PlayStateChangeEvent)

 [Floatping原创]

          以下是选取的部分代码,红色部分指明了为JarulyPlayer实例加入PlayStateChange事件和具体的方法体:

            //
            // JarulyPlayer
            // 
            this.JarulyPlayer = new AxMicrosoft.MediaPlayer.Interop.AxWindowsMediaPlayer();
            this.JarulyPlayer.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                        | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.JarulyPlayer.ContextMenuStrip = this.contextMenuStrip1;
            this.JarulyPlayer.Enabled = true;
            this.JarulyPlayer.Location = new System.Drawing.Point(0, 21);
            this.JarulyPlayer.Margin = new System.Windows.Forms.Padding(0);
            this.JarulyPlayer.MinimumSize = new System.Drawing.Size(400, 300);
            this.JarulyPlayer.Name = "JarulyPlayer";
            this.JarulyPlayer.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("JarulyPlayer.OcxState")));
            this.JarulyPlayer.Size = new System.Drawing.Size(438, 340);
            this.JarulyPlayer.Text = "JarulyPlayer";
            this.JarulyPlayer.PlayStateChange += new AxMicrosoft.MediaPlayer.Interop._WMPOCXEvents_PlayStateChangeEventHandler(JarulyPlayer_PlayStateChange);

        
 WMP9预置了一个“ PlayStateChange”这样的事件接口,在VS.NET中用 _WMPOCXEvents_PlayStateChangeEventHandler方法来实现。要注意的是它们所用的语法。下面是具体实现该接口的方法体:

 public void JarulyPlayer_PlayStateChange(object sender, AxMicrosoft.MediaPlayer.Interop._WMPOCXEvents_PlayStateChangeEvent e)
        {
            //TODO: 添加事件处理代码;
            MessageBox.Show("Changed");
        }

        附WMP核心类属性和方法:http://www.webtropy.com/articles/art14-2.asp?Interop=WMPCore
posted @ 2005-09-17 09:16  萍踪侠影  阅读(1763)  评论(0编辑  收藏  举报