summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2021-09-02 15:56:15 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-09-06 14:59:14 +0000
commit8c52de69adc7e3ed99e807749af4fb5a2026c502 (patch)
treebee247ec7e21140b2ab5041feebcc7a87100201b /examples
parentf558cb4132037b02c379f0bf8b768a3b10af4267 (diff)
Allow passing a media file as command line argument to the mediaplayer
It's often convenient to be able to pass the file to play back on the command line to the QML based mediaplayer. Change-Id: I1b77184a614cb6a32a7243e242b99fcdc1bae300 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io> (cherry picked from commit f1f53f209e9fa50c0a199bdbf1fa153e55611bb1) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'examples')
-rw-r--r--examples/multimedia/video/mediaplayer/main.cpp27
-rw-r--r--examples/multimedia/video/mediaplayer/main.qml1
2 files changed, 22 insertions, 6 deletions
diff --git a/examples/multimedia/video/mediaplayer/main.cpp b/examples/multimedia/video/mediaplayer/main.cpp
index e1c2f513e..957083235 100644
--- a/examples/multimedia/video/mediaplayer/main.cpp
+++ b/examples/multimedia/video/mediaplayer/main.cpp
@@ -50,19 +50,34 @@
#include <QGuiApplication>
#include <QQmlApplicationEngine>
-
+#include <QCommandLineParser>
+#include <QDir>
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
+ QCoreApplication::setApplicationName("MediaPlayer Example");
+ QCoreApplication::setOrganizationName("QtProject");
+ QCoreApplication::setApplicationVersion(QT_VERSION_STR);
+ QCommandLineParser parser;
+ parser.setApplicationDescription("Qt Quick MediaPlayer Example");
+ parser.addHelpOption();
+ parser.addVersionOption();
+ parser.addPositionalArgument("url", "The URL(s) to open.");
+ parser.process(app);
+
QQmlApplicationEngine engine;
const QUrl url(QStringLiteral("qrc:/main.qml"));
- QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
- &app, [url](QObject *obj, const QUrl &objUrl) {
- if (!obj && url == objUrl)
- QCoreApplication::exit(-1);
- }, Qt::QueuedConnection);
+
+ if (!parser.positionalArguments().isEmpty()) {
+ QUrl source = QUrl::fromUserInput(parser.positionalArguments().at(0), QDir::currentPath());
+ QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, [source](QObject *object, const QUrl &){
+ qDebug() << "setting source";
+ object->setProperty("source", source);
+ });
+ }
+
engine.load(url);
return app.exec();
diff --git a/examples/multimedia/video/mediaplayer/main.qml b/examples/multimedia/video/mediaplayer/main.qml
index c7e03b24a..6ea8b4135 100644
--- a/examples/multimedia/video/mediaplayer/main.qml
+++ b/examples/multimedia/video/mediaplayer/main.qml
@@ -61,6 +61,7 @@ Window {
height: 480
visible: true
title: qsTr("Multimedia Player")
+ property alias source: mediaPlayer.source
Popup {
id: mediaError