playback/player: qt: accept a list of uris or files as command line parameters

This commit is contained in:
Alexandre Moreno 2015-11-01 16:32:55 +08:00 committed by Sebastian Dröge
parent 1cebdf926c
commit 8853575547

View file

@ -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();
}