summaryrefslogtreecommitdiffstats
path: root/examples/multimedia/video/mediaplayer
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2021-09-02 15:56:15 +0200
committerPiotr Srebrny <piotr.srebrny@qt.io>2021-09-06 16:36:48 +0200
commitf1f53f209e9fa50c0a199bdbf1fa153e55611bb1 (patch)
tree1feb73402d991657085a53ec64a8df648635ae03 /examples/multimedia/video/mediaplayer
parent1253c57595ba112af356de4dfbee42a941263b1c (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. Pick-to: 6.2 Change-Id: I1b77184a614cb6a32a7243e242b99fcdc1bae300 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
Diffstat (limited to 'examples/multimedia/video/mediaplayer')
-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