QT with libVLC (播放器引擎)
(和树莓派 撸个电视盒子!)
VLC 官页 libVLC 说明 官方C++ API 文档 官方 wiki 官页教程
libVLC is a C library which can be embedded in your own applications. It works with most popular OS platforms, on both mobile and desktop. It is under the LGPL2.1 license.
libVLC versioning is inherently tied to the VLC app versioning. The current stable major version of libVLC is version 3, and the preview/development version is versio
libVLC SDK
静态库(LIB) 最新版的vlc安装目录中不再包含libvlc SDK 点击进入某个版本, 下载windows下7z格式压缩包, 解压即可得到相应的SDK;
运行库(DLL) 可在 VideoLAN 安装目录下: ./VLC 找到libvlc.dll 和 libvlccore.dll
libVLC 事件机制
创建事件管理器 - libvlc_event_manager_t,可选的方式有:
libvlc_media_event_manager():媒体相关的事件管理器。
比如,要监听媒体的改变状态(libvlc_MediaStateChanged),就需要用到它。
libvlc_media_list_event_manager():媒体列表相关的事件管理器。
比如,要监听媒体列表停止(libvlc_MediaListPlayerStopped),就需要用到它。
libvlc_media_player_event_manager():播放器相关的事件管理器。
比如,要监听播放器的音量(libvlc_MediaPlayerAudioVolume),就需要用到它。
踩坑指南
错误 -main libvlc error: No plugins found! Check your VLC installation.
指定 VLC_PLUGIN_PATH 环境变量为安装 VideoLAN 的plugins目录, 或者复制plugins 到运行根目录
qputenv("VLC_PLUGIN_PATH", "D:/libarry/vlc-3.0.16-win64-sdk/plugins/");
libvlc_media_player_stop 死锁
以内嵌的形式 libvlc_media_player_set_hwnd 自定义渲染窗口, 在停止调用libvlc_media_player_stop会造成死锁
// void *hwnd = (void *)this->ui->label->winId();
// qInfo()<<"MainWindow player hwnd= "<<hwnd;
// libvlc_media_player_set_hwnd(vlc_mediaPlayer, hwnd);
// libvlc_media_player_play(vlc_mediaPlayer);
// if(vlc_mediaPlayer){
// libvlc_media_player_stop(vlc_mediaPlayer);//内嵌窗的形式会造成死锁, 可能回调hwnd的某个事件, 在QT主线处理,造成的;
// qInfo()<<"MainWindow Release vlc_mediaPlayer";
// libvlc_media_player_release(vlc_mediaPlayer);
// }