[Winform]Media Player播放控制台控制,單擊事件截獲

來源:互聯網
上載者:User

標籤:ssi   準備就緒   back   準備   .sh   hid   sam   ansi   png   

摘要

在項目中有這樣的一個需求,需要在一台宣傳機器上迴圈播放一段視頻,並在體驗的使用者單擊滑鼠左鍵的時候推出全屏,可以讓使用者體驗電腦的其它功能。

解決方案

考慮到都是windows系統的,所以採用了windows內建的播放器,Windows Media Player Com組件作為視頻播放器。

但是,為了更好滿足需求,下面的播放控制台需要隱藏,該怎麼做呢?最後找到解決方案,設定播放器屬性

windowsMediaPlay.uiMode = "none";

迴圈播放的代碼,這裡為播放器添加播放清單,代碼如下:

 string[] filePaths = Directory.GetFiles(_videoDirPath).Where(x => x.EndsWith(".mp4") || x.EndsWith(".wmv")).ToArray();                //添加迴圈播放清單                foreach (var item in filePaths)                {                    windowsMediaPlay.currentPlaylist.appendItem(windowsMediaPlay.newMedia(item));                }                //不再工作列顯示                this.ShowInTaskbar = false;                this.FormClosing += VideoFrm_FormClosing;                windowsMediaPlay.ClickEvent += windowsMediaPlay_ClickEvent;                windowsMediaPlay.KeyUpEvent += windowsMediaPlay_KeyUpEvent;                windowsMediaPlay.StatusChange += windowsMediaPlay_StatusChange;                windowsMediaPlay.ErrorEvent += windowsMediaPlay_ErrorEvent;                windowsMediaPlay.DoubleClickEvent += windowsMediaPlay_DoubleClickEvent;                windowsMediaPlay.Ctlcontrols.play();

那麼,如何在使用者單擊的時候,讓程式最小化?

注意

在uiMode = "none"的情況下,單擊會觸發視頻暫停事件,並不會退出。視頻暫停,是不是視頻狀態變化了呢?所以在截獲單擊視頻事件,我們完全可以在視頻暫停時候,對其進行截獲。statechange事件對應的方法如下:

       void windowsMediaPlay_StatusChange(object sender, EventArgs e)        {            /*               * 0 Undefined Windows Media Player is in an undefined state.(未定義)                1 Stopped Playback of the current media item is stopped.(停止)                2 Paused Playback of the current media item is paused. When a media item is paused, resuming 
playback begins from the same location.(停留) 3 Playing The current media item is playing.(播放) 4 ScanForward The current media item is fast forwarding. 5 ScanReverse The current media item is fast rewinding. 6 Buffering The current media item is getting additional data from the server.(轉換) 7 Waiting Connection is established, but the server is not sending data. Waiting for session to begin.(暫停) 8 MediaEnded Media item has completed playback. (播放結束) 9 Transitioning Preparing new media item. 10 Ready Ready to begin playing.(準備就緒) 11 Reconnecting Reconnecting to stream.(重新串連) */ try { switch (windowsMediaPlay.playState) { case WMPLib.WMPPlayState.wmppsBuffering: break; case WMPLib.WMPPlayState.wmppsLast: break; case WMPLib.WMPPlayState.wmppsMediaEnded: break; case WMPLib.WMPPlayState.wmppsPaused: //單擊了視頻則退出 HideVideo(); break; case WMPLib.WMPPlayState.wmppsPlaying: if (!windowsMediaPlay.fullScreen) { windowsMediaPlay.fullScreen = true; } break; case WMPLib.WMPPlayState.wmppsReady: break; case WMPLib.WMPPlayState.wmppsReconnecting: break; case WMPLib.WMPPlayState.wmppsScanForward: break; case WMPLib.WMPPlayState.wmppsScanReverse: break; case WMPLib.WMPPlayState.wmppsStopped: break; case WMPLib.WMPPlayState.wmppsTransitioning: break; case WMPLib.WMPPlayState.wmppsUndefined: break; case WMPLib.WMPPlayState.wmppsWaiting: break; default: break; } } catch (Exception ex) { LogInfoData.WriteLog(new LogInfo { Dt = DateTime.Now, IsSend = false, Message = ex.Message, Op = "media_state_change_err" }); } }

關於雙擊全屏截獲的邏輯也可以在這裡處理,雙擊之前肯定會有一次單擊,所以在這裡也能進行雙擊最大化的處理。 

[Winform]Media Player播放控制台控制,單擊事件截獲

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.