diff options
author | Assam Boudjelthia <assam.boudjelthia@qt.io> | 2021-08-20 12:56:48 +0300 |
---|---|---|
committer | Assam Boudjelthia <assam.boudjelthia@qt.io> | 2021-08-23 16:31:55 +0000 |
commit | 14788016edea6d9062ffdd52c024eadb6c4e9403 (patch) | |
tree | 47c6b42dbbff7b594eaf2c28281854bc18951a35 | |
parent | 7038c860dbb3c329c567e5dc0a87d4063700d549 (diff) |
Make audiodecoder example usable on Android
Since this example is made as a command line tool, it won't be easy
using it on Android. This adds a QMessageBox to explain what the
example expects and does.
Pick-to: 6.2
Change-Id: I26af8b59a36de7c154baaeed5590b310f5bc5752
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
-rw-r--r-- | examples/multimedia/audiodecoder/CMakeLists.txt | 7 | ||||
-rw-r--r-- | examples/multimedia/audiodecoder/main.cpp | 34 |
2 files changed, 34 insertions, 7 deletions
diff --git a/examples/multimedia/audiodecoder/CMakeLists.txt b/examples/multimedia/audiodecoder/CMakeLists.txt index e78534aa2..7d9638549 100644 --- a/examples/multimedia/audiodecoder/CMakeLists.txt +++ b/examples/multimedia/audiodecoder/CMakeLists.txt @@ -18,6 +18,9 @@ set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/multimedia/audiodecoder") find_package(Qt6 COMPONENTS Core) find_package(Qt6 COMPONENTS Gui) find_package(Qt6 COMPONENTS Multimedia) +if(ANDROID) + find_package(Qt6 COMPONENTS Widgets) +endif() qt_add_executable(audiodecoder audiodecoder.cpp audiodecoder.h @@ -33,6 +36,10 @@ target_link_libraries(audiodecoder PUBLIC Qt::Multimedia ) +if(ANDROID) + target_link_libraries(audiodecoder PUBLIC Qt::Widgets) +endif() + install(TARGETS audiodecoder RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" diff --git a/examples/multimedia/audiodecoder/main.cpp b/examples/multimedia/audiodecoder/main.cpp index a219fffe3..f352bdea1 100644 --- a/examples/multimedia/audiodecoder/main.cpp +++ b/examples/multimedia/audiodecoder/main.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -54,13 +54,28 @@ #include <QDir> #include <QFileInfo> #include <QTextStream> +#ifdef Q_OS_ANDROID +#include <QApplication> +#include <QFileDialog> +#include <QMessageBox> +#endif #include <stdio.h> int main(int argc, char *argv[]) { +#ifdef Q_OS_ANDROID + QApplication app(argc, argv); +#else QCoreApplication app(argc, argv); +#endif + QFileInfo sourceFile; + QFileInfo targetFile; + bool isPlayback = false; + bool isDelete = false; + +#ifndef Q_OS_ANDROID QTextStream cout(stdout, QIODevice::WriteOnly); if (app.arguments().size() < 2) { cout << "Usage: audiodecoder [-p] [-pd] SOURCEFILE [TARGETFILE]\n"; @@ -70,9 +85,6 @@ int main(int argc, char *argv[]) return 0; } - bool isPlayback = false; - bool isDelete = false; - if (app.arguments().at(1) == "-p") isPlayback = true; else if (app.arguments().at(1) == "-pd") { @@ -80,9 +92,6 @@ int main(int argc, char *argv[]) isDelete = true; } - QFileInfo sourceFile; - QFileInfo targetFile; - int sourceFileIndex = (isPlayback || isDelete) ? 2 : 1; if (app.arguments().size() <= sourceFileIndex) { cout << "Error: source filename is not specified.\n"; @@ -95,6 +104,17 @@ int main(int argc, char *argv[]) else targetFile.setFile(sourceFile.dir().absoluteFilePath("out.wav")); +#else + + const QString message = "You will be prompted to select an audio file which will be" + "decoded and played back to you."; + QMessageBox messageBox(QMessageBox::Information, "Audio Decoder", message, QMessageBox::Ok); + messageBox.exec(); + sourceFile = QFileInfo(QFileDialog::getOpenFileName(messageBox.parentWidget(), + "Select Audio File")); + targetFile = QFileInfo("/data/local/tmp/out.wav"); + isPlayback = true; +#endif AudioDecoder decoder(isPlayback, isDelete, targetFile.absoluteFilePath()); QObject::connect(&decoder, &AudioDecoder::done, &app, &QCoreApplication::quit); |