diff options
author | Alexandre Moreno <alexmorenocano@gmail.com> | 2015-11-01 16:32:55 +0800 |
---|---|---|
committer | Sebastian Dröge <sebastian@centricular.com> | 2015-11-01 11:25:27 +0200 |
commit | 42078e5faeee0c6d3925f55d369546dd1c9d3dc5 (patch) | |
tree | 66038ebc7ab1c9cc37b59b46ac98bcebf7d6b809 | |
parent | e8c010a411a7eec1a4cf7a182ca6163e5d3f6885 (diff) |
qt: accept a list of uris or files as command line parameters
-rw-r--r-- | qt/main.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/qt/main.cpp b/qt/main.cpp index 5634732..999ddcb 100644 --- a/qt/main.cpp +++ b/qt/main.cpp @@ -20,6 +20,9 @@ #include <QApplication> #include <QQmlApplicationEngine> +#include <QCommandLineParser> +#include <QStringList> +#include <QUrl> #include "player.h" @@ -27,6 +30,20 @@ int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); + QCommandLineParser parser; + parser.setApplicationDescription("GstPlayer"); + parser.addHelpOption(); + parser.addPositionalArgument("urls", + QCoreApplication::translate("main", "URLs to play, optionally."), "[urls...]"); + parser.process(app); + + QList<QUrl> media_files; + + const QStringList args = parser.positionalArguments(); + foreach (const QString file, args) { + media_files << QUrl::fromUserInput(file); + } + qmlRegisterType<Player>("Player", 1, 0, "Player"); /* the plugin must be loaded before loading the qml file to register the @@ -44,9 +61,12 @@ int main(int argc, char *argv[]) QObject *rootObject = engine.rootObjects().first(); Player *player = rootObject->findChild<Player*>("player"); + QQuickItem *videoItem = rootObject->findChild<QQuickItem*>("videoItem"); player->setVideoOutput(videoItem); + if (!media_files.isEmpty()) + player->setPlaylist(media_files); return app.exec(); } |