参考:

https://blog.jianchihu.net/player-based-on-libvlc.html

自己在Qt上的实现:

头文件

libvlc_instance_t * m_inst;
...
...
HWND parentwnd;//播放句柄
QWidget* m_videoWdg;//播放窗口

 

源文件

BOOL CALLBACK EnumerateVLC(HWND hWndvlc, LPARAM lParam)
{

  if (!hWndvlc)
  {
    return FALSE;
  }

  EnableWindow(hWndvlc, FALSE);

  // And kill timer, i only need get this handle one time.
  //timer->stop();

  return TRUE;

}


构造函数里面:

{
  m_pTimer = nullptr;
  m_pTimer = new QTimer(this);
  connect(m_pTimer, SIGNAL(timeout()), this, SLOT(onTime()));

}


播放函数里面,获取到播放窗口的句柄

{
  m_inst = libvlc_new(0, NULL);
  ...
  ...
  HWND screen_hwnd = (HWND)m_videoWdg->winId();
  parentwnd =screen_hwnd;

  libvlc_media_player_set_hwnd(m_mp, screen_hwnd);

  .....

  m_pTimer->start(1000);

  Sleep(1);
}

//定时器函数
void StationCameraPlay::onTime()
{
  if (!parentwnd)
  {
    return;
  }

  EnumChildWindows(parentwnd, EnumerateVLC, NULL);

  m_pTimer->stop();
}

 

posted on 2019-04-24 18:24  邶风  阅读(1159)  评论(1编辑  收藏  举报