form中使用委託

 有關委託

private delegate void ExecuteDirective(string str, int persistence);//定義委託
 private delegate void ExecuteDirective2();//定義委託

 private void ReceiveMessage(string x)
        {
            string url =  url ="D:/film/1.rmvb";//完整路徑
            int  persistence = 20;//播放時間
            switch (x)
            {
                case "INSERT"://插入播放
                    ExecuteDirective fInsert = new ExecuteDirective(mediaInsert);
                    this.Invoke(fInsert, new object[] { url, persistence });

//調用form中的控件方法要使用invoke來調用,否則出錯
                    break;
                case "PAUSE"://暫停
                    ExecuteDirective2 fPause = new ExecuteDirective2(mediaPause);
                    this.Invoke(fPause );
                    break;
                case "PLAY"://從暫停處開始
                    ExecuteDirective2 fPlay = new ExecuteDirective2(mediaPlay);
                    this.Invoke(fPlay );
                    break;
            }
        }

 

 private void mediaInsert(string url, int persistence)

{

  axWindowsMediaPlayer1.URL = url;

}

 private void mediaPause()//暫停
        {
            axWindowsMediaPlayer1.Ctlcontrols.pause();
        }
        private WMPLib.WMPPlayState mediaState()//返回播放狀態
        {
            return axWindowsMediaPlayer1.playState;
        }
        private void mediaStop()//停止
        {
            axWindowsMediaPlayer1.Ctlcontrols.stop();
        }
        private void mediaPlay()//繼續播放
        {
            axWindowsMediaPlayer1.Ctlcontrols.play();
        }

 private void Play()//繼續播放
        {
            //播放列表

        }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章