diff options
author | Naoto Yamaguchi <naoto.yamaguchi@aisin.co.jp> | 2021-08-02 13:29:22 +0000 |
---|---|---|
committer | Naoto Yamaguchi <naoto.yamaguchi@aisin.co.jp> | 2021-08-02 13:29:22 +0000 |
commit | 8b78f7d07fc198cb0d059e39141e88474ba654cd (patch) | |
tree | f57b655822ae2b3ec022e63b5f4195a9c55e08fc /main.cpp |
Initial commit for momiplayer
momiplayer is a media player app based on agl media player app.
Signed-off-by: Naoto Yamaguchi <naoto.yamaguchi@aisin.co.jp>
Diffstat (limited to 'main.cpp')
-rw-r--r-- | main.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..6f9744d --- /dev/null +++ b/main.cpp @@ -0,0 +1,53 @@ +#include <QtCore/QDebug> +#include <QtCore/QDir> +#include <QtCore/QStandardPaths> +#include <QGuiApplication> +#include <QQmlApplicationEngine> +#include <QQmlContext> +#include <QtQml/qqml.h> +#include <QtQuickControls2/QQuickStyle> + + +#include "playlistwithmetadata.h" + +QVariantList readMusicFile(const QString &path) +{ + QVariantList ret; + QDir dir(path); + for (const auto &entry : dir.entryList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot, QDir::Name)) { + QFileInfo fileInfo(dir.absoluteFilePath(entry)); + if (fileInfo.isDir()) { + ret.append(readMusicFile(fileInfo.absoluteFilePath())); + } else if (fileInfo.isFile()) { + ret.append(QUrl::fromLocalFile(fileInfo.absoluteFilePath())); + } + } + return ret; +} + + +int main(int argc, char *argv[]) +{ + QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + + QGuiApplication app(argc, argv); + + qmlRegisterType<PlaylistWithMetadata>("MediaPlayer", 1, 0, "PlaylistWithMetadata"); + + QVariantList mediaFiles; + for (const auto &music : QStandardPaths::standardLocations(QStandardPaths::MusicLocation)) { + mediaFiles.append(readMusicFile(music)); + } + QQmlApplicationEngine engine; + QQmlContext *context = engine.rootContext(); + context->setContextProperty("mediaFiles", mediaFiles); + const QUrl url(QStringLiteral("qrc:/mediaplay.qml")); + QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, + &app, [url](QObject *obj, const QUrl &objUrl) { + if (!obj && url == objUrl) + QCoreApplication::exit(-1); + }, Qt::QueuedConnection); + engine.load(url); + + return app.exec(); +} |