QML中使用 VLC-Qt 播放网络视频流(附实例)

VLC-Qt库:一个在libVLC基础上结合了Qt框架的开源库。它提供了媒体播放的视频、音频处理控制的核心类,并提供基于QWidget和QML的GUI框架。QWidget中使用VLC方法见我博文:https://blog.csdn.net/zjgo007/article/details/106353952

此文介绍在QML中使用VLC播放网络流视频,效果图:

下载编译好的库VLC-Qt_1.1.0_win32_mingw.7z,解压到本地磁盘中,我解压路径为   E:\VLC\VLC

VLC-Qt 编译好的库下载地址:https://download.csdn.net/download/zjgo007/12461366,把解压后的bin目录下的dll库拷贝至Qt安装目录下的bin文件夹中 E:\Qt5.11.2\5.11.2\mingw53_32\bin。

新建工程,在.pro文件中添加VLC库文件(添加VLCQtCore库和VLCQtQml)在main.cpp文件中添加插件所处路径。

完整代码:

main.cpp:

#include <QtCore/QCoreApplication>
#include <QtGui/QGuiApplication>
#include <QtQuick/QQuickView>

#include <VLCQtCore/Common.h>
#include <VLCQtQml/QmlVideoPlayer.h>

int main(int argc, char *argv[])
{
    QCoreApplication::setApplicationName("VLC-QML播放器");
    QCoreApplication::setAttribute(Qt::AA_X11InitThreads);

    QGuiApplication app(argc, argv);
    VlcCommon::setPluginPath("E:/VLC/VLC/bin/plugins");
    VlcQmlVideoPlayer::registerPlugin();

    QQuickView quickView;
    quickView.setSource(QUrl(QStringLiteral("qrc:/main.qml")));
    quickView.setResizeMode(QQuickView::SizeRootObjectToView);
    quickView.show();

    return app.exec();
}

main.qml:

import QtQuick 2.0
import VLCQt 1.0

Rectangle {
    width: 640
    height: 480
    color: "black"

    VlcVideoPlayer {
        id: vidwidget
        anchors.fill: parent
        url: "http://ivi.bupt.edu.cn/hls/cctv1hd.m3u8"
    }
}

完整Demo地址:

https://download.csdn.net/download/zjgo007/12654483

猜你喜欢

转载自blog.csdn.net/zjgo007/article/details/107534075