summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDoris Verria <doris.verria@qt.io>2021-06-13 17:06:45 +0200
committerDoris Verria <doris.verria@qt.io>2021-06-14 12:54:39 +0200
commit594fd10b492bad8f9e6e045dbe3b50d236266684 (patch)
tree84298f7168da98065063a8292aad31a7f2597308
parentc4e782df9dc88ab531dad47a44bc48058e7e628c (diff)
AudioDecoder example: Don't start event loop in case of error
If an error is set on the decoder before starting the application's event loop, this will cause the application to hang. Check for errors and return if there are any. Change-Id: Ib2d96559f8712db43973612f0e428f6d71438f02 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
-rw-r--r--examples/multimedia/audiodecoder/audiodecoder.cpp5
-rw-r--r--examples/multimedia/audiodecoder/audiodecoder.h1
-rw-r--r--examples/multimedia/audiodecoder/main.cpp3
3 files changed, 9 insertions, 0 deletions
diff --git a/examples/multimedia/audiodecoder/audiodecoder.cpp b/examples/multimedia/audiodecoder/audiodecoder.cpp
index 401b41bfd..891499ea2 100644
--- a/examples/multimedia/audiodecoder/audiodecoder.cpp
+++ b/examples/multimedia/audiodecoder/audiodecoder.cpp
@@ -112,6 +112,11 @@ void AudioDecoder::stop()
m_decoder.stop();
}
+QAudioDecoder::Error AudioDecoder::getError()
+{
+ return m_decoder.error();
+}
+
void AudioDecoder::setTargetFilename(const QString &fileName)
{
m_targetFilename = fileName;
diff --git a/examples/multimedia/audiodecoder/audiodecoder.h b/examples/multimedia/audiodecoder/audiodecoder.h
index b6c8dc36f..cd27a9bf3 100644
--- a/examples/multimedia/audiodecoder/audiodecoder.h
+++ b/examples/multimedia/audiodecoder/audiodecoder.h
@@ -68,6 +68,7 @@ public:
void setSource(const QString &fileName);
void start();
void stop();
+ QAudioDecoder::Error getError();
void setTargetFilename(const QString &fileName);
diff --git a/examples/multimedia/audiodecoder/main.cpp b/examples/multimedia/audiodecoder/main.cpp
index 5bb240b94..a219fffe3 100644
--- a/examples/multimedia/audiodecoder/main.cpp
+++ b/examples/multimedia/audiodecoder/main.cpp
@@ -88,6 +88,7 @@ int main(int argc, char *argv[])
cout << "Error: source filename is not specified.\n";
return 0;
}
+
sourceFile.setFile(app.arguments().at(sourceFileIndex));
if (app.arguments().size() > sourceFileIndex + 1)
targetFile.setFile(app.arguments().at(sourceFileIndex + 1));
@@ -99,6 +100,8 @@ int main(int argc, char *argv[])
&app, &QCoreApplication::quit);
decoder.setSource(sourceFile.absoluteFilePath());
decoder.start();
+ if (decoder.getError() != QAudioDecoder::NoError)
+ return 0;
return app.exec();
}