zoukankan      html  css  js  c++  java
  • VS2010下 LibVLC开发环境搭建

    LibVLC环境的搭建 

    最近又 LIBVLC 做一个视频播放器,封装成ActiveX控件,之前做过一个基于OpenCV的播放器(只解码视频,音频不用,OpenCV也没有解码音频的功能)。

    到目前位置完成的功能有

    设置文件名、播放、暂停/继续、获得视频长度、获得视频播放时间、设置视频播放位置(时间)、逐帧播放、停止、设置下一个播放的绝对时间(年 月 日 时 分 秒 毫秒)、设置视频开始位置的绝对时间(年 月 日 时  分 秒  毫秒)、全屏/恢复、获得视频播放速度、设置视频播放速度(快、慢)、截图; 以及视频的开始位置绝对时间的7个属性(年 月 日 时 分 秒 毫秒)以及他们的Get/Set方法。

    在做全屏的时候遇到一个问题,libvlc给了三个和全屏有关的API,如下:

     

    //切换全屏 / 恢复
    LIBVLC_API void libvlc_toggle_fullscreen( libvlc_media_player_t *p_mi );
     
    //设置全屏 / 恢复,由b_fullscreen决定
    LIBVLC_API void libvlc_set_fullscreen( libvlc_media_player_t *p_mi, int b_fullscreen );
     
    //获取是否全屏
    LIBVLC_API int libvlc_get_fullscreen( libvlc_media_player_t *p_mi );

     

     

    但是、可是、可但是,在该头文件中又说了:

    * @warning With most window managers, only a top-level windows can be in
    * full-screen mode. Hence, this function will not operate properly if
    * libvlc_media_player_set_xwindow() was used to embed the video in a
    * non-top-level window. In that case, the embedding window must be reparented
    * to the root window <b>before</b> fullscreen mode is enabled. You will want
    * to reparent it back to its normal parent when disabling fullscreen.

     

    歌词大意是:在许多窗口管理器中,只有一个top-level window可以设置为full-screen模式。 因此当使用函数libvlc_media_player_set_xwindow() 来将视频嵌入到一个non-top-level window的时候,可能不会起作用(编者注:确实是这样,确实特么不起作用)。 这种情况下,这个嵌入的窗口必须将其父窗口设置为root window(编者注:Windows下的root window应该就是desktop窗口了)以便将全屏模式启用。 当取消全屏的时候你就要重新将他的父窗口设置为普通的窗口。

     

    ---------------------------------------------------------------

    接着说

    在全屏的时候,需要将控件窗口的设置为top-level window,方法就是去除WS_CHILD属性,然后将其父窗口设置为desktop。

    恢复时,将其位置放在原来的合适位置,将其父窗口设置为原来的,将其窗口风格恢复。

     
    
    if (b == true)
        {
            //此时不是全屏, 要全屏
            m_hWndParent = GetParent()->m_hWnd;     //父窗口句柄
            int cx = GetSystemMetrics(SM_CXSCREEN);
            int cy = GetSystemMetrics(SM_CYSCREEN);
            GetWindowRect(&m_rectPlayer);                  //本视频窗口大小 
    
            //获得其窗口风格
            m_lStyle = GetWindowLong(m_hWnd, GWL_STYLE);
            m_lStyleEx = GetWindowLong(m_hWnd, GWL_EXSTYLE);
            SetWindowLong(m_hWnd, GWL_STYLE, m_lStyle | ~WS_CHILD | ~WS_CHILDWINDOW | ~WS_BORDER); 
            SetWindowLong(m_hWnd, GWL_EXSTYLE, m_lStyleEx | ~WS_EX_CLIENTEDGE);
    
            HWND hWndDesktop = GetDesktopWindow()->GetSafeHwnd();
            HWND hParentWnd = ::SetParent(m_hWnd, hWndDesktop);
            HWND hTemp = ::GetParent(m_hWnd);  
    
            ::MoveWindow(m_hWnd, 0, 0, cx, cy, TRUE);    
            //::SetWindowPos(m_hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_DEFERERASE | SWP_NOMOVE | SWP_NOSIZE); 
        }
        else
        {
            SetParent(FromHandle(m_hWndParent));    //恢复原来的父窗口
            CPoint leftTop(m_rectPlayer.TopLeft());
            CPoint bottomRight(m_rectPlayer.BottomRight());
            ::ScreenToClient(m_hWndParent, &leftTop);
            ::ScreenToClient(m_hWndParent, &bottomRight);
    
            //恢复其窗口属性
            SetWindowLong(m_hWnd, GWL_STYLE, m_lStyle);
            SetWindowLong(m_hWnd, GWL_EXSTYLE, m_lStyleEx);
    
            ::MoveWindow(m_hWnd, leftTop.x, leftTop.y, m_rectPlayer.Width(), m_rectPlayer.Height(), TRUE);
            ::SetWindowPos(m_hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
        }

     

     

     

     

    环境搭建

    1、去官网下载播放器(安装后附带SDK)

        地址 http://www.videolan.org/

     

    2、安装完成后,将安装目录下 SDKinclude 和 SDKlib 拷贝到工程目录下

     

     

     

    拷贝到工程目录下

    当前图目录为工程目录,即解决方案所在目录

     

     

    3、将VLC安装目录下的plugins目录、libvlc.dll、libvlccore.dll 拷贝至工程的debug 或 release目录下

     

     

    拷贝至debug目录下

     

     4、在VS的项目属性里,添加头文件和库文件的目录

     

     

     5、在工程的合适位置引用头文件、导入库

    #include <vlc/vlc.h>
    #pragma comment(lib, "libvlc.lib")
    #pragma comment(lib, "libvlccore.lib")

      以上

  • 相关阅读:
    【转】Android中的颜色设置
    hashlib —— Python 的 md5 和 sha1 加密
    caffe 在 windows 下的配置(scriptsuild_win.cmd)
    caffe 在 windows 下的配置(scriptsuild_win.cmd)
    windows 批处理脚本(batch scripting)
    windows 批处理脚本(batch scripting)
    matlab 辅助函数 —— 文件下载与文件解压
    matlab 辅助函数 —— 文件下载与文件解压
    翻译的艺术 —— 句子的翻译(意译)
    翻译的艺术 —— 句子的翻译(意译)
  • 原文地址:https://www.cnblogs.com/cuish/p/3772850.html
Copyright © 2011-2022 走看看