3 * Copyright (C) 2015 Alexandre Moreno <alexmorenocano@gmail.com>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
21 #include <QApplication>
22 #include <QQmlApplicationEngine>
23 #include <QQmlProperty>
25 #include <QCommandLineParser>
26 #include <QStringList>
30 int main(int argc, char *argv[])
32 /* Use QApplication instead of QGuiApplication since the latter is needed
33 * for widgets like the QFileDialog to work */
34 QApplication app(argc, argv);
37 QCommandLineParser parser;
38 parser.setApplicationDescription("GstPlayer");
39 parser.addHelpOption();
40 parser.addPositionalArgument("urls",
41 QCoreApplication::translate("main", "URLs to play, optionally."), "[urls...]");
44 QList<QUrl> media_files;
46 const QStringList args = parser.positionalArguments();
47 foreach (const QString file, args) {
48 media_files << QUrl::fromUserInput(file);
51 /* the plugin must be loaded before loading the qml file to register the
52 * GstGLVideoItem qml item
53 * FIXME Add a QQmlExtensionPlugin into qmlglsink to register GstGLVideoItem
54 * with the QML engine, then remove this */
56 GstElement *sink = gst_element_factory_make ("qmlglsink", NULL);
57 gst_object_unref(sink);
60 QQmlApplicationEngine engine;
61 engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
63 QObject *rootObject = engine.rootObjects().first();
65 QObject *player = rootObject->findChild<QObject*>("player");
66 QObject *videoItem = rootObject->findChild<QObject*>("videoItem");
68 v.setValue<QObject*>(videoItem);
69 QQmlProperty(player, "videoOutput").write(v);
71 if (!media_files.isEmpty()) {
73 v.setValue<QList<QUrl>>(media_files);
74 QQmlProperty(player, "playlist").write(QVariant (v));