Windows平台RTMP|RTSP播放器实现画面全屏功能

简介: 我们在Windows平台实现RTSP或者RTMP播放的时候,有个功能是绕不开的,那就是播放窗口全屏。本文就以大牛直播SDK(官方)的Windows播放器为例,大概讲下大概实现:

我们在Windows平台实现RTSP或者RTMP播放的时候,有个功能是绕不开的,那就是播放窗口全屏。本文就以大牛直播SDK(官方)的Windows播放器为例,大概讲下大概实现:


全屏播放需要考虑的点不多:


第一:视频播放后,全屏的意义;


第二:全屏后,是否等比例显示,我们的设计原则是,之前等比例显示的,继续等比例显示,之前铺满的,继续铺满;


第三:ESC退出全屏。


本文以C++的demo为例,具体实现如下:

void nt_wrapper_render_wnd::FullScreenSwitch()
{
  if ( !::IsWindow(m_hWnd) )
    return;
  if (player_handle_ != nullptr)
  {
    player_api_.SetRenderARGBLogo(player_handle_, nullptr, 0, 0, 0, 0, 0, 0, 0);
  }
  if ( !IsFullScreen() )
  {
    if ( !IsCanFullScreen() )
      return;
    auto old_wnd = GetParent();
    if ( old_wnd == NULL )
      return;
    old_parent_wnd_ = old_wnd->m_hWnd;
    ASSERT(::IsWindow(old_parent_wnd_));
    GetWindowRect(&old_rect_);
    old_wnd->ScreenToClient(old_rect_);
    HMONITOR hMonitor = ::MonitorFromWindow(m_hWnd, MONITOR_DEFAULTTONEAREST);
    if (hMonitor == NULL)
      return;
    MONITORINFOEX mi;
    mi.cbSize = sizeof(mi);
    if ( !GetMonitorInfo(hMonitor, &mi) )
      return;
    ::SetParent(m_hWnd, NULL);
    auto wnd_styles = GetWindowLongPtr(m_hWnd, GWL_STYLE);
    wnd_styles = wnd_styles & (~WS_CHILD);  
    wnd_styles |= WS_POPUP;
    ::SetWindowLongPtr(m_hWnd, GWL_STYLE, wnd_styles);
    // 隐藏老窗口
    ::ShowWindow(old_parent_wnd_, SW_HIDE);
    is_full_screen_ = true;
    ::SetWindowPos(m_hWnd, HWND_TOP, mi.rcMonitor.left,
      mi.rcMonitor.top,
      mi.rcMonitor.right - mi.rcMonitor.left,
      mi.rcMonitor.bottom - mi.rcMonitor.top,
      SWP_FRAMECHANGED);
    ::SetForegroundWindow(m_hWnd);
    ::RedrawWindow(m_hWnd, NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW
      | RDW_ERASE);
    ::RedrawWindow(NULL, NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW
      | RDW_ERASE);
  }
  else
  {
    ::ShowWindow(old_parent_wnd_, SW_SHOW);
    auto wnd_styles = GetWindowLongPtr(m_hWnd, GWL_STYLE);
    wnd_styles = wnd_styles & (~WS_POPUP);
    wnd_styles |= WS_CHILD;
    auto ret = SetWindowLongPtr(m_hWnd, GWL_STYLE, wnd_styles);
    ::SetParent(m_hWnd, old_parent_wnd_);
    is_full_screen_ = false;
    MoveWindow(old_rect_, TRUE);
  }
}

ESC处理:

void nt_wrapper_render_wnd::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
  // TODO: Add your message handler code here and/or call default
  // 全屏的时候,按ESC将退出全屏
  if ( nChar == VK_ESCAPE )
  {
    if ( IsFullScreen() )
    {
      FullScreenSwitch();
    }
  }
  CWnd::OnChar(nChar, nRepCnt, nFlags);
}

C#的实现也非常简单,感兴趣的可自行研究。

相关文章
|
4月前
|
监控 编译器 Windows
Qt5实现Windows平台串口通信
Qt5实现Windows平台串口通信
|
4月前
|
安全 Linux iOS开发
Binary Ninja 5.1.8104 (macOS, Linux, Windows) - 反编译器、反汇编器、调试器和二进制分析平台
Binary Ninja 5.1.8104 (macOS, Linux, Windows) - 反编译器、反汇编器、调试器和二进制分析平台
502 53
Binary Ninja 5.1.8104 (macOS, Linux, Windows) - 反编译器、反汇编器、调试器和二进制分析平台
|
4月前
|
Linux API iOS开发
Binary Ninja 4.2.6455 (macOS, Linux, Windows) - 反编译器、反汇编器、调试器和二进制分析平台
Binary Ninja 4.2.6455 (macOS, Linux, Windows) - 反编译器、反汇编器、调试器和二进制分析平台
342 14
Binary Ninja 4.2.6455 (macOS, Linux, Windows) - 反编译器、反汇编器、调试器和二进制分析平台
|
4月前
|
安全 数据安全/隐私保护 虚拟化
Windows Server 2022 中文版、英文版下载 (2025 年 10 月更新)
Windows Server 2022 中文版、英文版下载 (2025 年 10 月更新)
1143 2
Windows Server 2022 中文版、英文版下载 (2025 年 10 月更新)
|
4月前
|
安全 Unix 物联网
Windows 7 & Windows Server 2008 R2 简体中文版下载 (2025 年 10 月更新)
Windows 7 & Windows Server 2008 R2 简体中文版下载 (2025 年 10 月更新)
512 0
Windows 7 & Windows Server 2008 R2 简体中文版下载 (2025 年 10 月更新)
|
4月前
|
存储 SQL 人工智能
Windows Server 2025 中文版、英文版下载 (2025 年 10 月更新)
Windows Server 2025 中文版、英文版下载 (2025 年 10 月更新)
707 0
|
5月前
|
运维 安全 网络安全
Windows Server 2019拨号“找不到设备”?Error 1058解决指南
Windows Server 2019拨号报错1058?别急!这不是硬件故障,而是关键服务被禁用。通过“服务依存关系”排查,依次启动“安全套接字隧道协议”“远程接入连接管理”和“路由与远程访问”服务,仅需4步即可恢复PPPoE或VPN拨号功能,轻松解决网络中断问题。
467 1
|
5月前
|
存储 SQL 人工智能
Windows Server 2025 中文版、英文版下载 (2025 年 9 月更新)
Windows Server 2025 中文版、英文版下载 (2025 年 9 月更新)
2519 3
Windows Server 2025 中文版、英文版下载 (2025 年 9 月更新)
|
5月前
|
安全 Unix 物联网
Windows 7 & Windows Server 2008 R2 简体中文版下载 (2025 年 9 月更新)
Windows 7 & Windows Server 2008 R2 简体中文版下载 (2025 年 9 月更新)
869 2