[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

posted @   wolfy  阅读(5508)  评论(1编辑  收藏  举报
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
历史上的今天:
2014-06-20 [杂谈]记第一次出差有感
点击右上角即可分享
微信分享提示