[Winform]Media Player組件全屏播放的設置


摘要

在設置程序開始運行時,讓視頻全屏播放時,直接設置

windowsMediaPlay.fullScreen = true;

會報錯,代碼如下

                windowsMediaPlay.URL = _videoPath;
                windowsMediaPlay.Ctlcontrols.play();
                windowsMediaPlay.fullScreen = true;
                windowsMediaPlay.ClickEvent += windowsMediaPlay_ClickEvent;
                windowsMediaPlay.KeyUpEvent += windowsMediaPlay_KeyUpEvent;
                windowsMediaPlay.StatusChange += windowsMediaPlay_StatusChange;

錯誤

抱着相信微軟的心情,就在猜想,可能是位置不對,是不是必須視頻在播放中才可以設置全屏?

所以在視頻狀態變化的事件中,這樣設置

        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.(重新連接)
*/ //判斷視頻是否已停止播放 if ((int)windowsMediaPlay.playState == 1) { //停頓2秒鍾再重新播放 System.Threading.Thread.Sleep(1000); //重新播放 windowsMediaPlay.Ctlcontrols.play(); } else if ((int)windowsMediaPlay.playState == 3) { windowsMediaPlay.fullScreen = true; } }

MSDN

Remarks

For full-screen mode to work properly when embedding the Windows Media Player control, the video display area must have a height and width of at least one pixel. If uiMode is set to "mini" or "full", the height of the control itself must be 65 or greater to accommodate the video display area in addition to the user interface.

If uiMode is set to "invisible", then setting this property to true raises an error and does not affect the behavior of the control.

During full-screen playback, Windows Media Player hides the mouse cursor when enableContextMenu equals false and uiMode equals "none".

If uiMode is set to "full" or "mini", Windows Media Player displays transport controls in full-screen mode when the mouse cursor moves. After a brief interval of no mouse movement, the transport controls are hidden. If uiMode is set to "none", no controls are displayed in full-screen mode.

Note  Displaying transport controls in full-screen mode requires the Windows XP operating system.
 

If transport controls are not displayed in full-screen mode, then Windows Media Player automatically exits full-screen mode when playback stops.

參考

https://msdn.microsoft.com/en-us/library/windows/desktop/dd562419(v=vs.85).aspx


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM