vlc-qt

前言

VLC-Qt:一个结合了 Qt 应用程序和 libVLC 的免费开源库。它包含了用于媒体播放的核心类,以及用于更快速地进行媒体播放器开发的一些 GUI 类。

下载对应版本

我用的是msvc2015的版本

然后解压到 VLC-Qt-Install(下面会用到),它里面有三个子文件夹:

  • include:包含了所需的头文件
  • lib:包含所需的 lib 文件
  • bin:包含了所需的 dll 文件(动态库及插件)

修改pro文件

LIBS       += -lVLCQtCore -lVLCQtQml
LIBS += -L$$PWD/vlc/lib/ -lVLCQtCore -lVLCQtQml

INCLUDEPATH += $$PWD/vlc/include

修改main文件

#include <QApplication>
#include <QQmlApplicationEngine>
#include <QtWebEngine>
#include "main_server.h"
#include "Log.h"
#include "interactive.h"
#include "config_file.h"

//加这两行
#include "VLCQtCore/Common.h"
#include "VLCQtQml/QmlVideoPlayer.h"


int main(int argc, char *argv[])
{
#if defined(Q_OS_WIN)
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif

    QApplication app(argc, argv);
    //LOG::InstallMessageHandler(app);

    QtWebEngine::initialize();
    QNetworkProxyFactory::setUseSystemConfiguration(false);


    //qmlRegisterType<interactive>("Interactive",1,0,"Interactive");

    QQmlApplicationEngine engine;

    interactive* interactor = interactive::getInstance();
    engine.rootContext()->setContextProperty("gInteractor",interactor);

	//加这两行
    VlcCommon::setPluginPath(app.applicationDirPath() + "/plugins");
    VlcQmlVideoPlayer::registerPlugin();



    config_file_init();


    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    if (engine.rootObjects().isEmpty())
        return -1;


    main_server server;

    return app.exec();
}

修改qml

import QtQuick 2.10
import QtQuick.Controls 2.2
import QtMultimedia 5.9
import VLCQt 1.0

Rectangle{
    width: parent.width;
    height: parent.height;
    color: "black";

    VlcVideoPlayer {
            id: mediaPlayer
            anchors.fill: parent
            autoplay:true
            url:{
                gInteractor.getVideoUrl();
            }
            volume:50
    }

    VideoOutput {
        id: video;
        anchors.fill: parent;
        source: mediaPlayer;
        fillMode:VideoOutput.Stretch// 缩放到目标尺寸
        //source: mymediaplayer
        //Component.onCompleted: {
        //    mymediaplayer.play();
       // }
    }


}


# qml  

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×